#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]);
auto lt = fields.begin(), pos = fields.begin(), rt = fields.begin() + 1;
ll left, right;
left = right = 0;
ll cur = 0;
ll output = 0;
while (rt != fields.end())
{
while (b < cur)
{
// cout << *pos << " " << *lt << " " << cur << endl;
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++;
}
}
// cout << lt - fields.begin() << " " << pos - fields.begin() << " " << rt - fields.begin() << " " << cur << " " << left << " " << right << endl;
output = max(output, left + right + 1);
if (pos + 1 != fields.end()) {
// cout << cur << " ";
cur += (*(pos + 1) - *pos) * (left + 1);
// cout << cur << " ";
cur += (*pos - *(pos + 1)) * (right);
// cout << cur << endl;
}
pos++, left++, right--;
}
// cerr << output << "\n";
return output;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
316 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 |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Incorrect |
1 ms |
308 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
312 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
308 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
308 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
316 KB |
Output is correct |
13 |
Correct |
1 ms |
304 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
852 KB |
Output is correct |
2 |
Correct |
3 ms |
852 KB |
Output is correct |
3 |
Correct |
14 ms |
2884 KB |
Output is correct |
4 |
Correct |
16 ms |
2868 KB |
Output is correct |
5 |
Correct |
6 ms |
1488 KB |
Output is correct |
6 |
Correct |
6 ms |
1476 KB |
Output is correct |
7 |
Correct |
14 ms |
2652 KB |
Output is correct |
8 |
Correct |
11 ms |
2624 KB |
Output is correct |
9 |
Correct |
6 ms |
1360 KB |
Output is correct |
10 |
Correct |
5 ms |
1360 KB |
Output is correct |
11 |
Correct |
12 ms |
2864 KB |
Output is correct |
12 |
Correct |
13 ms |
2860 KB |
Output is correct |
13 |
Incorrect |
5 ms |
1488 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |