#include "ricehub.h"
#include<bits/stdc++.h>
using namespace std;
vector<int> pos;
vector<long long> pref;
long long budget;
int limit;
bool existWithT(int T){
auto findGoodSegment = [&](int l,int r){
int best = pos[(l+r)/2];
int pos_best = (l+r)/2;
long long right_part=pref[r]-pref[pos_best];
right_part-= (r-pos_best)*best;
//cout<<"r"<<right_part<<endl;
long long left_part=(pos_best-l+1)*best;
left_part-=(pref[pos_best]-(l==0?0:pref[l-1]));
//cout<<"l"<<left_part<<endl;
long long computedScore = right_part+left_part;
if(computedScore<=budget)return true;
return false;
};
if(findGoodSegment(0,T-1))return true;
for(int right=T;right<pos.size();right++){
if(findGoodSegment(right-T+1,right))return true;
}
return false;
}
int besthub(int R, int L, int X[], long long B)
{
budget = B;
pos.resize(R);
pref.resize(R);
limit = L;
long long act=0;
for(int i = 0;i<R;i++){
pos[i] = X[i];
act+=pos[i];
pref[i]=act;
}
sort(pos.begin(),pos.end());
int low = 1;
int high = R;
while ((high-low)>1){
int mid = (low+high)/2;
if(existWithT(mid)){
low = mid;
}else{
high = mid;
}
}
if(existWithT(high)){
return high;
}else{
return low;
}
}
Compilation message
ricehub.cpp: In function 'bool existWithT(int)':
ricehub.cpp:29:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for(int right=T;right<pos.size();right++){
| ~~~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
596 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
444 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
0 ms |
344 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
448 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
600 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
3 ms |
604 KB |
Output is correct |
3 |
Correct |
10 ms |
3676 KB |
Output is correct |
4 |
Correct |
10 ms |
3740 KB |
Output is correct |
5 |
Correct |
8 ms |
3420 KB |
Output is correct |
6 |
Correct |
6 ms |
3420 KB |
Output is correct |
7 |
Correct |
9 ms |
4444 KB |
Output is correct |
8 |
Correct |
9 ms |
4444 KB |
Output is correct |
9 |
Correct |
7 ms |
3320 KB |
Output is correct |
10 |
Correct |
7 ms |
3420 KB |
Output is correct |
11 |
Correct |
11 ms |
4700 KB |
Output is correct |
12 |
Correct |
10 ms |
4700 KB |
Output is correct |
13 |
Correct |
6 ms |
3420 KB |
Output is correct |
14 |
Correct |
6 ms |
3420 KB |
Output is correct |
15 |
Correct |
8 ms |
4188 KB |
Output is correct |
16 |
Correct |
8 ms |
4188 KB |
Output is correct |
17 |
Correct |
9 ms |
4480 KB |
Output is correct |
18 |
Correct |
9 ms |
4440 KB |
Output is correct |
19 |
Correct |
10 ms |
4700 KB |
Output is correct |
20 |
Correct |
10 ms |
4548 KB |
Output is correct |