#include <bits/stdc++.h>
using namespace std;
#define SZ(v) ((int)(v).size())
using ll = long long;
const int MAXN = 1e5+1;
ll prefixSum[MAXN];
ll cntFields, maxCor, budget;
ll cor[MAXN];
ll getCost(int l, int r)
{
int mid = (l+r)/2;
ll cost = (2*mid-l-r) * cor[mid] + prefixSum[r+1] + prefixSum[l] - prefixSum[mid] - prefixSum[mid+1];
return cost;
}
bool can(int want)
{
for (int i(0); i + want <= cntFields; ++i)
if (getCost(i, i+want-1) <= budget)
return true;
return false;
}
int besthub(int c, int m, int co[], ll b)
{
budget = b;
cntFields = c;
maxCor = m;
for (int i(0); i < cntFields; ++i)
cor[i] = co[i];
for (int i(0); i < cntFields; ++i)
prefixSum[i+1] = prefixSum[i] + cor[i];
int r(0);
int ret(0);
for (int l(0); l < cntFields; ++l)
{
r = max(r, l);
while (r < cntFields and getCost(l, r) <= budget)
++r;
ret = max(ret, r-l);
}
return ret;
int lo(0), up(cntFields);
while (lo < up)
{
int mid = (lo+up+1)/2;
if (can(mid)) lo = mid;
else up = mid-1;
}
return lo;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
256 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
0 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
0 ms |
384 KB |
Output is correct |
26 |
Correct |
0 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
768 KB |
Output is correct |
2 |
Correct |
3 ms |
768 KB |
Output is correct |
3 |
Correct |
21 ms |
2296 KB |
Output is correct |
4 |
Correct |
21 ms |
2300 KB |
Output is correct |
5 |
Correct |
8 ms |
1280 KB |
Output is correct |
6 |
Correct |
11 ms |
1280 KB |
Output is correct |
7 |
Correct |
14 ms |
2304 KB |
Output is correct |
8 |
Correct |
14 ms |
2304 KB |
Output is correct |
9 |
Correct |
7 ms |
1280 KB |
Output is correct |
10 |
Correct |
7 ms |
1280 KB |
Output is correct |
11 |
Correct |
22 ms |
2304 KB |
Output is correct |
12 |
Correct |
18 ms |
2296 KB |
Output is correct |
13 |
Correct |
8 ms |
1280 KB |
Output is correct |
14 |
Correct |
10 ms |
1280 KB |
Output is correct |
15 |
Correct |
17 ms |
1792 KB |
Output is correct |
16 |
Correct |
17 ms |
1792 KB |
Output is correct |
17 |
Correct |
17 ms |
2048 KB |
Output is correct |
18 |
Correct |
18 ms |
2048 KB |
Output is correct |
19 |
Correct |
17 ms |
2176 KB |
Output is correct |
20 |
Correct |
18 ms |
2176 KB |
Output is correct |