#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
#define fin cin
#define fout cout
//ifstream fin("x.in"); ofstream fout("x.out");
typedef long long i64;
const int nmax = 1e5;
static i64 s[nmax + 1];
bool check (int n, int v[], i64 b, int x) {
for (int i = x; i <= n; ++ i) {
int y = (i - x + 1);
int mij = (y + i) / 2;
if (b >= s[i] - s[mij] - 1LL * (i - mij) * v[mij] + 1LL * (mij - y + 1) * v[mij] - (s[mij] - s[y - 1])) {
return 1;
}
}
return 0;
}
int besthub (int n, int l, int v[], i64 b) {
for (int i = 1; i <= n; ++ i)
s[i] = s[i - 1] + v[i - 1];
int n2;
for (n2 = 1; (n2 << 1) <= n; n2 <<= 1) {
}
int ans = 0;
for (int step = n2; step > 0; step >>= 1) {
if (ans + step <= n && check(n, v, b, ans + step))
ans += step;
}
return ans;
}
/*int k[5] = {1, 2, 10, 12, 14};
int main() {
cout << besthub(5, 20, k, 6) << "\n";
return 0;
}*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
256 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
3 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Correct |
3 ms |
384 KB |
Output is correct |
24 |
Correct |
3 ms |
384 KB |
Output is correct |
25 |
Correct |
3 ms |
384 KB |
Output is correct |
26 |
Correct |
3 ms |
384 KB |
Output is correct |
27 |
Correct |
2 ms |
384 KB |
Output is correct |
28 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
3 ms |
384 KB |
Output is correct |
18 |
Correct |
3 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
384 KB |
Output is correct |
20 |
Correct |
3 ms |
384 KB |
Output is correct |
21 |
Correct |
4 ms |
384 KB |
Output is correct |
22 |
Correct |
3 ms |
384 KB |
Output is correct |
23 |
Correct |
3 ms |
384 KB |
Output is correct |
24 |
Correct |
3 ms |
384 KB |
Output is correct |
25 |
Correct |
3 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
4 ms |
384 KB |
Output is correct |
28 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
768 KB |
Output is correct |
2 |
Correct |
7 ms |
768 KB |
Output is correct |
3 |
Correct |
18 ms |
2560 KB |
Output is correct |
4 |
Correct |
19 ms |
2560 KB |
Output is correct |
5 |
Correct |
13 ms |
1280 KB |
Output is correct |
6 |
Correct |
13 ms |
1280 KB |
Output is correct |
7 |
Correct |
19 ms |
2300 KB |
Output is correct |
8 |
Correct |
14 ms |
2304 KB |
Output is correct |
9 |
Correct |
9 ms |
1152 KB |
Output is correct |
10 |
Correct |
11 ms |
1124 KB |
Output is correct |
11 |
Correct |
22 ms |
2552 KB |
Output is correct |
12 |
Correct |
19 ms |
2552 KB |
Output is correct |
13 |
Correct |
10 ms |
1280 KB |
Output is correct |
14 |
Correct |
11 ms |
1280 KB |
Output is correct |
15 |
Correct |
16 ms |
2040 KB |
Output is correct |
16 |
Correct |
21 ms |
2048 KB |
Output is correct |
17 |
Correct |
27 ms |
2296 KB |
Output is correct |
18 |
Correct |
23 ms |
2304 KB |
Output is correct |
19 |
Correct |
28 ms |
2424 KB |
Output is correct |
20 |
Correct |
20 ms |
2432 KB |
Output is correct |