[Offer收割]编程练习赛1 register

Ended

Participants:955

Verdict:Accepted
Score:100 / 100
Submitted:2016-03-06 14:32:43

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long lld;
const int MAXQ = 1e14;
const int N = 100010;
int p[N];
priority_queue<int> buffer;
lld cal(int k, int n)
{
    lld ret = 0;
    int cnt = 1;
    for (int i = 0; i < n; i++) {
        if (buffer.size() >= k) {
            ret += buffer.top() * cnt;
            cnt += 1;
            buffer.pop();
        }
        buffer.push(p[i]);
    }
    while (!buffer.empty()) {
        ret += buffer.top() * cnt;
        cnt += 1;
        buffer.pop();
    }
    return ret;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX