#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
int besthub(int R, int L, int X[], long long B)
{
long long prefix[100001];
prefix[0] = X[0];
if (R == 0)
{
return 0;
}
for (int i=1; i<R; i++)
{
long long add = X[i];
prefix[i] = prefix[i-1] + add;
}
long long cost = 0;
int leng = 1;
long long l = 0, r = 1;
while (r < R)
{
long long med = (l+r)/2;
long long val = X[med];
cost = 0;
if (med != l)
{
if (l==0)
{
cost += (val)*(med-l)- prefix[med-1];
}
else
{
cost += (val)*(med-l)- (prefix[med-1]-prefix[l-1]);
}
}
if (med != r)
{
cost += prefix[r] - prefix[med] - (r-med)*(val);
}
if (cost <= B)
{
leng = max(leng, (int)(r - l + 1));
r++;
}
else
{
l++;
r++;
}
}
return leng;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
1084 KB |
Output is correct |
8 |
Correct |
1 ms |
980 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
1080 KB |
Output is correct |
11 |
Correct |
1 ms |
980 KB |
Output is correct |
12 |
Correct |
1 ms |
1080 KB |
Output is correct |
13 |
Correct |
1 ms |
980 KB |
Output is correct |
14 |
Correct |
1 ms |
1076 KB |
Output is correct |
15 |
Correct |
1 ms |
980 KB |
Output is correct |
16 |
Correct |
1 ms |
980 KB |
Output is correct |
17 |
Correct |
1 ms |
980 KB |
Output is correct |
18 |
Correct |
1 ms |
980 KB |
Output is correct |
19 |
Correct |
1 ms |
980 KB |
Output is correct |
20 |
Correct |
1 ms |
980 KB |
Output is correct |
21 |
Correct |
1 ms |
980 KB |
Output is correct |
22 |
Correct |
1 ms |
980 KB |
Output is correct |
23 |
Correct |
1 ms |
1084 KB |
Output is correct |
24 |
Correct |
1 ms |
980 KB |
Output is correct |
25 |
Correct |
1 ms |
980 KB |
Output is correct |
26 |
Correct |
1 ms |
980 KB |
Output is correct |
27 |
Correct |
1 ms |
980 KB |
Output is correct |
28 |
Correct |
1 ms |
1084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
1084 KB |
Output is correct |
8 |
Correct |
1 ms |
980 KB |
Output is correct |
9 |
Correct |
1 ms |
1108 KB |
Output is correct |
10 |
Correct |
1 ms |
980 KB |
Output is correct |
11 |
Correct |
1 ms |
980 KB |
Output is correct |
12 |
Correct |
1 ms |
1084 KB |
Output is correct |
13 |
Correct |
1 ms |
1088 KB |
Output is correct |
14 |
Correct |
1 ms |
980 KB |
Output is correct |
15 |
Correct |
1 ms |
980 KB |
Output is correct |
16 |
Correct |
1 ms |
1080 KB |
Output is correct |
17 |
Correct |
1 ms |
980 KB |
Output is correct |
18 |
Correct |
1 ms |
980 KB |
Output is correct |
19 |
Correct |
1 ms |
980 KB |
Output is correct |
20 |
Correct |
1 ms |
980 KB |
Output is correct |
21 |
Correct |
1 ms |
1108 KB |
Output is correct |
22 |
Correct |
1 ms |
1108 KB |
Output is correct |
23 |
Correct |
1 ms |
1108 KB |
Output is correct |
24 |
Correct |
1 ms |
1108 KB |
Output is correct |
25 |
Correct |
1 ms |
1092 KB |
Output is correct |
26 |
Correct |
1 ms |
1108 KB |
Output is correct |
27 |
Correct |
1 ms |
1124 KB |
Output is correct |
28 |
Correct |
1 ms |
1108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1108 KB |
Output is correct |
2 |
Correct |
4 ms |
1240 KB |
Output is correct |
3 |
Correct |
11 ms |
1612 KB |
Output is correct |
4 |
Correct |
11 ms |
1536 KB |
Output is correct |
5 |
Correct |
5 ms |
1356 KB |
Output is correct |
6 |
Correct |
5 ms |
1376 KB |
Output is correct |
7 |
Correct |
10 ms |
1600 KB |
Output is correct |
8 |
Correct |
10 ms |
1500 KB |
Output is correct |
9 |
Correct |
5 ms |
1384 KB |
Output is correct |
10 |
Correct |
5 ms |
1344 KB |
Output is correct |
11 |
Correct |
11 ms |
1596 KB |
Output is correct |
12 |
Correct |
11 ms |
1596 KB |
Output is correct |
13 |
Correct |
5 ms |
1364 KB |
Output is correct |
14 |
Correct |
7 ms |
1368 KB |
Output is correct |
15 |
Correct |
10 ms |
1460 KB |
Output is correct |
16 |
Correct |
11 ms |
1476 KB |
Output is correct |
17 |
Correct |
11 ms |
1488 KB |
Output is correct |
18 |
Correct |
11 ms |
1500 KB |
Output is correct |
19 |
Correct |
10 ms |
1568 KB |
Output is correct |
20 |
Correct |
10 ms |
1452 KB |
Output is correct |