#include "ricehub.h"
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> pii;
int besthub(int n, int L, int X[], long long b)
{
vector <ll> fields;
for (int i = 0; i < n; i++) fields.emplace_back(X[i]);
if (n <= 5e3)
{
ll cur = 0;
if (n == 1) return 1;
int output = 0;
ll p;
int left, right;
for (int i = 0; i < n; i++)
{
p = fields[i];
cur = b;
left = i - 1, right = i + 1;
while (true)
{
if (left < 0 && right == n)
{
break;
} else if (left < 0)
{
if (cur >= fields[right] - p) {
cur -= fields[right] - p;
right++;
} else break;
} else if (right == n)
{
if (cur >= p - fields[left]) {
cur -= p - fields[left];
left--;
} else break;
}
else if (p - fields[left] < fields[right] - p)
{
if (cur >= p - fields[left]) {
cur -= p - fields[left];
left--;
} else break;
} else {
if (cur >= fields[right] - p) {
cur -= fields[right] - p;
right++;
} else break;
}
}
output = max(output, right - left - 1);
}
return output;
}
auto lt = fields.begin(), pos = fields.begin(), rt = fields.begin() + 1;
ll left, right;
left = right = 0;
ll cur = 0;
ll output = 0;
while (pos != fields.end())
{
while (b < cur)
{
cur -= *pos - *lt;
lt++, left--;
}
while (rt != fields.end() && cur + *rt - *pos <= b)
{
cur += *rt - *pos;
right++, rt++;
}
while (rt != fields.end() && (*pos - *lt) > (*rt - *pos))
{
left--, right++, lt++, rt++;
while (rt != fields.end() && cur + *rt - *pos <= b)
{
cur += *rt - *pos;
right++, rt++;
}
}
output = max(output, left + right + 1);
if (pos + 1 != fields.end()) {
cur += (*(pos + 1) - *pos) * (left + 1);
cur += (*pos - *(pos + 1)) * (right);
}
pos++, left++, right--;
}
return output;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
2 ms |
212 KB |
Output is correct |
14 |
Correct |
2 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
3 ms |
212 KB |
Output is correct |
18 |
Correct |
3 ms |
212 KB |
Output is correct |
19 |
Correct |
4 ms |
212 KB |
Output is correct |
20 |
Correct |
4 ms |
212 KB |
Output is correct |
21 |
Correct |
4 ms |
436 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
39 ms |
340 KB |
Output is correct |
24 |
Correct |
33 ms |
340 KB |
Output is correct |
25 |
Correct |
78 ms |
340 KB |
Output is correct |
26 |
Correct |
79 ms |
424 KB |
Output is correct |
27 |
Correct |
22 ms |
436 KB |
Output is correct |
28 |
Correct |
25 ms |
412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
724 KB |
Output is correct |
2 |
Correct |
2 ms |
724 KB |
Output is correct |
3 |
Correct |
11 ms |
1756 KB |
Output is correct |
4 |
Correct |
13 ms |
2884 KB |
Output is correct |
5 |
Correct |
5 ms |
1476 KB |
Output is correct |
6 |
Correct |
6 ms |
1488 KB |
Output is correct |
7 |
Correct |
12 ms |
2616 KB |
Output is correct |
8 |
Correct |
11 ms |
2596 KB |
Output is correct |
9 |
Correct |
6 ms |
1360 KB |
Output is correct |
10 |
Correct |
6 ms |
1360 KB |
Output is correct |
11 |
Correct |
13 ms |
2884 KB |
Output is correct |
12 |
Correct |
13 ms |
2820 KB |
Output is correct |
13 |
Incorrect |
6 ms |
1520 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |