#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
#define ll long long
int besthub(int R, int L, int V[], ll B)
{
vector<int> X(R);
vector<int> Best(R);
for (int i = 0; i < R; i++)
X[i] = V[i];
int c1 = 0, c2 = 0;
ll sum = 0;
while (c2 < R && sum + X[c2] - X[0] <= B)
{
sum += X[c2] - X[0];
c2++;
}
c2--;
Best[0] = c2 + 1;
for (int i = 1; i < R; i++)
{
if (X[i] == X[i - 1])
{
Best[i] = Best[i - 1];
if (c2 < i)
c2 = i;
continue;
}
sum += (i - c1) * (X[i] - X[i - 1]) - (c2 - (i - 1)) * (X[i] - X[i - 1]);
if (c2 < i)
c2 = i;
while (sum > B)
{
if (X[i] - X[c1] >= X[c2] - X[i])
{
sum -= X[i] - X[c1];
c1++;
}
else
{
sum -= X[c2] - X[i];
c2++;
}
}
bool done_changes = true;
while (done_changes)
{
done_changes = false;
int p1 = c1 - 1, p2 = c2 + 1;
if (p2 < R && (p1 < 0 || X[p2] - X[i] <= X[i] - X[p1]))
{
if (sum + X[p2] - X[i] <= B)
{
sum += X[p2] - X[i];
c2++;
done_changes = true;
continue;
}
}
if (p1 >= 0 && (p2 >= R || X[i] - X[p1] < X[p2] - X[i]))
{
if (sum + X[i] - X[p1] <= B)
{
sum += X[i] - X[p1];
c1--;
done_changes = true;
continue;
}
}
if (p2 < R && X[p2] - X[i] < X[i] - X[c1])
{
sum -= X[i] - X[c1];
sum += X[p2] - X[i];
c1++;
c2++;
done_changes = true;
continue;
}
if (p1 >= 0 && X[i] - X[p1] < X[c2] - X[i])
{
sum -= X[c2] - X[i];
sum += X[i] - X[p1];
c2--;
c1--;
done_changes = true;
continue;
}
}
Best[i] = c2 - c1 + 1;
}
int Max = Best[0];
for (int i = 0; i < R; i++)
Max = max(Max, Best[i]);
return Max;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
448 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
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 |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
504 KB |
Output is correct |
5 |
Correct |
0 ms |
600 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
360 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
552 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 |
348 KB |
Output is correct |
13 |
Correct |
0 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 |
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 |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
448 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 |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
352 KB |
Output is correct |
6 |
Correct |
0 ms |
356 KB |
Output is correct |
7 |
Correct |
0 ms |
356 KB |
Output is correct |
8 |
Correct |
0 ms |
356 KB |
Output is correct |
9 |
Correct |
0 ms |
360 KB |
Output is correct |
10 |
Correct |
0 ms |
352 KB |
Output is correct |
11 |
Correct |
0 ms |
352 KB |
Output is correct |
12 |
Correct |
0 ms |
356 KB |
Output is correct |
13 |
Correct |
0 ms |
352 KB |
Output is correct |
14 |
Correct |
1 ms |
356 KB |
Output is correct |
15 |
Correct |
0 ms |
452 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
352 KB |
Output is correct |
18 |
Correct |
0 ms |
352 KB |
Output is correct |
19 |
Correct |
0 ms |
352 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
352 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
356 KB |
Output is correct |
26 |
Correct |
1 ms |
460 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
600 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
10 ms |
4500 KB |
Output is correct |
4 |
Correct |
9 ms |
4444 KB |
Output is correct |
5 |
Correct |
5 ms |
3388 KB |
Output is correct |
6 |
Correct |
5 ms |
3160 KB |
Output is correct |
7 |
Correct |
8 ms |
4188 KB |
Output is correct |
8 |
Correct |
8 ms |
4192 KB |
Output is correct |
9 |
Correct |
6 ms |
3276 KB |
Output is correct |
10 |
Correct |
5 ms |
3288 KB |
Output is correct |
11 |
Correct |
11 ms |
4444 KB |
Output is correct |
12 |
Incorrect |
12 ms |
4320 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |