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

Ended

Participants:955

Verdict:Accepted
Score:100 / 100
Submitted:2016-03-06 16:46:13

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<cstring>
#include<queue>
#include<iostream>
#include<algorithm>
#define maxn 100500
using namespace std;
typedef long long LL;
int n,ans=-1;
LL m;
LL a[maxn];
priority_queue<LL> q;
void init()
{
    scanf("%d%lld",&n,&m) ;
    for (int i=1;i<=n;++i) 
        scanf("%lld",&a[i]);
} 
bool check(int x)
{
     LL cnt=0,sum=0;
     for (int i=1;i<=n;++i)
     {
//      if (sum>m)          return 0;
        q.push(a[i]);
        if (i>=x)
        {
            sum+=(++cnt)*q.top();
            q.pop();
        }
     }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX