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

Ended

Participants:955

Verdict:Accepted
Score:100 / 100
Submitted:2016-03-06 15:41:05

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 <queue>
#include <iostream>
#include <functional>
using namespace std;
bool calcPunish(int size, vector<int> list, long long Q)
{
    priority_queue<int> p;
    if (size == 0) {
        size = 1;
    }
    for (int i = 0; i < size; i++) {
        p.push(list[i]);
    }
    long long punish = 0;
    long long index = 1;
    for (int i = size; i < list.size(); i++) {
        punish += index * p.top();
        if (punish > Q)
            return false;
        p.pop();
        p.push(list[i]);
        index++;
    }
    while (!p.empty()) {
        punish += index * p.top();
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX