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

Ended

Participants:955

Verdict:Accepted
Score:100 / 100
Submitted:2016-03-06 14:20:07

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 <cstdio>
#include <queue>
using namespace std;
int n;
long long q;
int data[1000010];
int main()
{
    while(scanf("%d%lld", &n, &q) != EOF)
    {
        for(int i = 0; i < n; ++i)
            scanf("%d", &data[i]);
        int l = 1, r = n;
        int min_ans = n + 1;
        while(l <= r)
        {
            int mid = (l + r) >> 1;
            priority_queue<int> pq;
            long long sum = 0;
            int i;
            for(i = 0; i < mid; ++i)
                pq.push(data[i]);
            long long j = 1;
            for(; i < n; ++i)
            {
                sum += pq.top()*j;
                pq.pop();
                pq.push(data[i]);
                ++j;
            }
            while(!pq.empty())
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX