#include "ricehub.h"
#include<algorithm>
using namespace std;
int besthub(int r, int l, int x[], long long b){
int duz=0;
long long cena=0;
int res=0;
for(int i=0;i<r;i++){
while(i-duz-1>=0 && i+duz+1<r){
if(cena+abs(x[i]-x[i-duz-1])+abs(x[i]-x[i+duz+1])>b) break;
cena+=abs(x[i]-x[i-duz-1])+abs(x[i]-x[i+duz+1]);
duz++;
}
res=max(res,2*duz+1);
if(i-duz-1>=0){
if(cena+abs(x[i]-x[i-duz-1])<=b) res=max(res,2*duz+2);
}
if(i+duz+1<r){
if(cena+abs(x[i]-x[i+duz+1])<=b) res=max(res,2*duz+2);
}
if(i<r-1 && duz>0){
cena+=x[i+1]-x[i];
cena-=abs(x[i+1]-x[i-duz]);
cena-=abs(x[i+1]-x[i+duz]);
duz--;
}
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
292 KB |
Output is correct |
7 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
292 KB |
Output is correct |
5 |
Incorrect |
0 ms |
296 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |