#include "ricehub.h"
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define ii pair<ll,ll>
using namespace std;
int besthub(int R, int L, int X[], long long B)
{
int ans=0;
for (int i = 0; i < R; ++i)
{
int idx=i,comp=1;
ll rem=B;
priority_queue<pair<ii,ll>,vector<pair<ii,ll>>,greater<pair<ii,ll> > > q;
if(idx-1>=0)q.push({{X[idx]-X[idx-1],idx-1},0});
if(idx+1<R)q.push({{X[idx+1]-X[idx],idx+1},1});
while(!q.empty()){
pair<ii,ll> front =q.top();
q.pop();
ll C=front.fi.fi,id=front.fi.se;
if(C>rem)break;
rem-=C,comp++;
if(front.se&&id+1<R)
q.push({{X[id+1]-X[id]+C,id+1},1});
if(!front.se&&id-1>=0)
q.push({{X[id]-X[id-1]+C,id-1},0});
}
//cerr<<i<<" "<<comp<<"\n";
ans=max(ans,comp);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
256 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
256 KB |
Output is correct |
20 |
Correct |
2 ms |
256 KB |
Output is correct |
21 |
Correct |
3 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
400 KB |
Output is correct |
23 |
Correct |
7 ms |
380 KB |
Output is correct |
24 |
Correct |
7 ms |
376 KB |
Output is correct |
25 |
Correct |
8 ms |
376 KB |
Output is correct |
26 |
Correct |
8 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
4 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
21 ms |
256 KB |
Output is correct |
4 |
Correct |
20 ms |
424 KB |
Output is correct |
5 |
Correct |
3 ms |
360 KB |
Output is correct |
6 |
Correct |
3 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
380 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
27 ms |
376 KB |
Output is correct |
14 |
Correct |
25 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
19 ms |
376 KB |
Output is correct |
18 |
Correct |
18 ms |
376 KB |
Output is correct |
19 |
Correct |
29 ms |
372 KB |
Output is correct |
20 |
Correct |
28 ms |
376 KB |
Output is correct |
21 |
Correct |
36 ms |
376 KB |
Output is correct |
22 |
Correct |
37 ms |
376 KB |
Output is correct |
23 |
Correct |
629 ms |
376 KB |
Output is correct |
24 |
Correct |
574 ms |
376 KB |
Output is correct |
25 |
Correct |
637 ms |
504 KB |
Output is correct |
26 |
Correct |
621 ms |
376 KB |
Output is correct |
27 |
Correct |
324 ms |
376 KB |
Output is correct |
28 |
Correct |
324 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
504 KB |
Output is correct |
2 |
Correct |
50 ms |
612 KB |
Output is correct |
3 |
Execution timed out |
1083 ms |
1784 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |