#include "ricehub.h"
#include <bits/stdc++.h>
#define debug(args...) //fprintf(stderr, args)
typedef long long int lli;
using namespace std;
const int maxn = 2e5;
int s[maxn],cs[maxn],I,J,SUM;
int besthub(int R, int L, int X[], long long int B)
{
s[0] = X[0];
for(int x = 1; x < R; x++)
s[x] = s[x-1] + X[x];
cs[R-1] = X[R-1];
for(int x = R-1; x >= 0; x--)
cs[x] = cs[x+1] + X[x];
int i = 0;
int j = 0;
lli resp = 0;
while(j < R)
{
int med = (i + j) / 2;
lli sumEsq = (cs[i] - cs[med]) - ((med - i)*(X[R-1] - X[med]));
lli sumDir = (s[j] - s[med]) - ((j - med)*(X[med] - X[0]));
lli sum = sumEsq + sumDir;
lli r = j - i + 1;
debug("%d - %d(%d) %d %d -%d-\n",i,j,sum,sumEsq,sumDir,med);
if(sum <= B)
{
resp = max(resp, r);
j++;
}
else if(i == j)
{
j++;
}
else i++;
}
return resp;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |