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

Ended

Participants:955

Verdict:Accepted
Score:100 / 100
Submitted:2016-03-06 15:04:20

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 <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector <int>    VI;
typedef pair <int,int>  PII;
#define FOR(i,x,y)  for(int i = x;i < y;++ i)
#define IFOR(i,x,y) for(int i = x;i > y;-- i)
#define fi  first
#define se  second
const int maxn = 100010;
int n,k;
LL p[maxn],Q;
bool work(){
    priority_queue <LL> q;
    FOR(i,1,k+1)    q.push(p[i]);
    int num = k,cnt = 1;
    LL ans = 0;
    while(!q.empty()){
        LL u = q.top(); q.pop();
        if(num < n) q.push(p[++num]);       
        ans += u*cnt;
        cnt ++;
    }
    if(ans > Q) return false;
    return true;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX