#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int besthub(int n, int l, int x[], long long money)
{
int a = 0;
int b = 0;
ll cost = 0;
int best = 0;
while (b + 1 < n && cost + x[(b + 1)] - x[0] <= money)
{
cost += x[(b + 1)] - x[0];
b++;
}
int left = 0;
int right = b;
best = max(best, b - a + 1);
//cout << "oj " << cost << endl;
for (int i = 1; i < n; i++)
{
cost -= (ll) right * (x[i] - x[i - 1]);
left++;
cost += (ll) left * (x[i] - x[i - 1]);
right--;
while(cost > money)
{
cost -= x[i] - x[a];
a++;
left--;
}
while((b + 1 < n && x[b + 1] - x[i] + cost < money) || (b + 1 < n && x[i] - x[a] > x[b + 1] - x[i]))
{
if (x[b + 1] - x[i] + cost < money)
{
cost += x[b + 1] - x[i];
b++;
right++;
} else
{
cost -= x[i] - x[a];
a++;
left--;
cost += x[b + 1] - x[i];
b++;
right++;
}
}
//cout << "oj " << a << " " << b << " " << cost << endl;
best = max(best, b - a + 1);
}
return best;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
388 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
0 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
0 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
0 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
0 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
364 KB |
Output is correct |
2 |
Correct |
3 ms |
364 KB |
Output is correct |
3 |
Correct |
16 ms |
748 KB |
Output is correct |
4 |
Correct |
16 ms |
748 KB |
Output is correct |
5 |
Correct |
7 ms |
492 KB |
Output is correct |
6 |
Correct |
7 ms |
492 KB |
Output is correct |
7 |
Correct |
14 ms |
748 KB |
Output is correct |
8 |
Correct |
15 ms |
748 KB |
Output is correct |
9 |
Correct |
7 ms |
492 KB |
Output is correct |
10 |
Correct |
11 ms |
492 KB |
Output is correct |
11 |
Correct |
17 ms |
748 KB |
Output is correct |
12 |
Correct |
17 ms |
748 KB |
Output is correct |
13 |
Correct |
8 ms |
492 KB |
Output is correct |
14 |
Correct |
8 ms |
492 KB |
Output is correct |
15 |
Correct |
12 ms |
620 KB |
Output is correct |
16 |
Correct |
12 ms |
620 KB |
Output is correct |
17 |
Correct |
14 ms |
620 KB |
Output is correct |
18 |
Correct |
15 ms |
620 KB |
Output is correct |
19 |
Correct |
15 ms |
748 KB |
Output is correct |
20 |
Correct |
16 ms |
748 KB |
Output is correct |