#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll niz[100000];
ll mani;
int N;
bool moze(int x){
ll trencost=0;
int trenmid, r=x, l=1;
trenmid = (x+2)/2;
for(int i=1; i<=x; i++){
trencost += abs(niz[i]-niz[trenmid]);
}
if(trencost <= mani) return true;
while(r < N){
r++;
trenmid++;
trencost -= niz[trenmid-1]-niz[l];
trencost += niz[r]-niz[trenmid];
l++;
trencost += (niz[trenmid]-niz[trenmid-1])*(trenmid-l);
trencost -= (niz[trenmid]-niz[trenmid-1])*(r-trenmid);
if(trencost <= mani) return true;
}
return false;
}
int besthub(int n, int L, int X[], long long B){
N = n;
mani = B;
for(int i=1; i<=n; i++){
niz[i] = X[i-1];
}
int l=1, r=n;
int maxres=1;
while(l <= r){
int mid = (l+r)/2;
if(moze(mid)){
l = mid+1;
maxres = max(maxres, mid);
}
else r = mid-1;
}
return maxres;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
380 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
380 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
1 ms |
220 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
1 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
368 KB |
Output is correct |
14 |
Correct |
2 ms |
368 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
504 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
6 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
376 KB |
Output is correct |
23 |
Correct |
3 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
0 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
424 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 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 |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 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 |
380 KB |
Output is correct |
15 |
Correct |
2 ms |
380 KB |
Output is correct |
16 |
Correct |
2 ms |
428 KB |
Output is correct |
17 |
Correct |
3 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
3 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
376 KB |
Output is correct |
23 |
Correct |
3 ms |
504 KB |
Output is correct |
24 |
Correct |
6 ms |
504 KB |
Output is correct |
25 |
Correct |
3 ms |
504 KB |
Output is correct |
26 |
Correct |
3 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
504 KB |
Output is correct |
28 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
632 KB |
Output is correct |
2 |
Correct |
5 ms |
760 KB |
Output is correct |
3 |
Correct |
22 ms |
2524 KB |
Output is correct |
4 |
Correct |
20 ms |
2552 KB |
Output is correct |
5 |
Correct |
10 ms |
1272 KB |
Output is correct |
6 |
Correct |
12 ms |
1272 KB |
Output is correct |
7 |
Correct |
18 ms |
2296 KB |
Output is correct |
8 |
Correct |
16 ms |
2296 KB |
Output is correct |
9 |
Correct |
10 ms |
1144 KB |
Output is correct |
10 |
Correct |
10 ms |
1148 KB |
Output is correct |
11 |
Correct |
22 ms |
2552 KB |
Output is correct |
12 |
Correct |
22 ms |
2524 KB |
Output is correct |
13 |
Correct |
12 ms |
1272 KB |
Output is correct |
14 |
Correct |
9 ms |
1272 KB |
Output is correct |
15 |
Correct |
18 ms |
2040 KB |
Output is correct |
16 |
Correct |
17 ms |
1912 KB |
Output is correct |
17 |
Correct |
20 ms |
2364 KB |
Output is correct |
18 |
Correct |
20 ms |
2296 KB |
Output is correct |
19 |
Correct |
20 ms |
2424 KB |
Output is correct |
20 |
Correct |
21 ms |
2424 KB |
Output is correct |