#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 pos = fields.begin(), lt = fields.begin(), rt = fields.begin() + 1;
ll cur = 0;
if (n == 1) return 1;
long output = 0;
while (rt != fields.end())
{
while (cur > b)
{
cur -= *pos - *lt;
lt++;
}
while (rt != fields.end() && cur + (*rt - *pos) <= b)
{
cur += (*rt - *pos);
rt++;
}
while (rt != fields.end() && (*pos - *lt) > (*rt - *pos))
{
cur += (*rt - *pos) - (*pos - *lt);
lt++, rt++;
while (rt != fields.end() && cur + (*rt - *pos) <= b)
{
cur += (*rt - *pos);
rt++;
}
}
// cout << lt - fields.begin() << " " << pos - fields.begin() << " " << rt - fields.begin() << "\n";
output = max(output, ((rt - fields.begin()) - (lt - fields.begin())));
pos++;
if (rt != fields.end())
{
// cout << "c";
// cout << cur << " ";
cur += (*pos - *(pos - 1)) * ((pos - fields.begin()) - (lt - fields.begin()));
// cout << cur << " ";
cur += (*(pos - 1) - *pos) * ((rt - fields.begin()) - (pos - fields.begin()));
// cout << cur << "\n";
}
}
// cerr << output << "\n";
return output;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
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 |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
0 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 |
0 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 |
308 KB |
Output is correct |
19 |
Correct |
1 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 |
308 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Incorrect |
1 ms |
312 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
312 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 |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
304 KB |
Output is correct |
11 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
15 |
Correct |
0 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 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
852 KB |
Output is correct |
2 |
Correct |
3 ms |
820 KB |
Output is correct |
3 |
Correct |
13 ms |
2868 KB |
Output is correct |
4 |
Correct |
12 ms |
2880 KB |
Output is correct |
5 |
Correct |
6 ms |
1488 KB |
Output is correct |
6 |
Correct |
9 ms |
1496 KB |
Output is correct |
7 |
Correct |
15 ms |
2648 KB |
Output is correct |
8 |
Correct |
11 ms |
2540 KB |
Output is correct |
9 |
Correct |
5 ms |
1432 KB |
Output is correct |
10 |
Correct |
6 ms |
1360 KB |
Output is correct |
11 |
Correct |
12 ms |
2884 KB |
Output is correct |
12 |
Correct |
12 ms |
2892 KB |
Output is correct |
13 |
Correct |
6 ms |
1452 KB |
Output is correct |
14 |
Correct |
6 ms |
1472 KB |
Output is correct |
15 |
Correct |
9 ms |
2468 KB |
Output is correct |
16 |
Correct |
12 ms |
2636 KB |
Output is correct |
17 |
Correct |
12 ms |
2700 KB |
Output is correct |
18 |
Correct |
19 ms |
2712 KB |
Output is correct |
19 |
Correct |
19 ms |
2752 KB |
Output is correct |
20 |
Correct |
17 ms |
2824 KB |
Output is correct |