# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
917391 |
2024-01-28T04:38:08 Z |
406 |
Feast (NOI19_feast) |
C++17 |
|
112 ms |
5876 KB |
#include <bits/stdc++.h>
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ar = array<int, 2>;
const int64_t INF = 1ll << 60;
const int N = 3e5 + 5;
int n, k, a[N], ans;
bool check(const int O, bool f = 0) {
ar dp{0, 0}, F{0, 0};
int s = 0;
FOR(i, 0, n) {
s += a[i];
F = max(F, ar{dp[0] - s, dp[1]});
dp = max(dp, ar{s + F[0] - O, F[1] - 1});
}
if (f) ans = max(ans, dp[0] + k * O);
return -dp[1] >= k;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> k;
FOR(i, 0, n) cin >> a[i];
int l = 0, r = 1ll << 50;
while (r - l > 1) {
int m = l + r >> 1;
if (check(m)) l = m;
else r = m;
}
check(l, 1);
cout << ans << '\n';
return 0;
}
Compilation message
feast.cpp: In function 'int main()':
feast.cpp:31:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
31 | int m = l + r >> 1;
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
4068 KB |
Output is correct |
2 |
Correct |
42 ms |
4336 KB |
Output is correct |
3 |
Correct |
45 ms |
4444 KB |
Output is correct |
4 |
Correct |
44 ms |
4436 KB |
Output is correct |
5 |
Correct |
59 ms |
4428 KB |
Output is correct |
6 |
Correct |
42 ms |
4204 KB |
Output is correct |
7 |
Correct |
41 ms |
4176 KB |
Output is correct |
8 |
Correct |
42 ms |
4444 KB |
Output is correct |
9 |
Correct |
49 ms |
4176 KB |
Output is correct |
10 |
Correct |
43 ms |
4416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
3416 KB |
Output is correct |
2 |
Correct |
32 ms |
3540 KB |
Output is correct |
3 |
Correct |
30 ms |
3420 KB |
Output is correct |
4 |
Correct |
34 ms |
3412 KB |
Output is correct |
5 |
Correct |
38 ms |
5612 KB |
Output is correct |
6 |
Correct |
31 ms |
3672 KB |
Output is correct |
7 |
Correct |
33 ms |
4108 KB |
Output is correct |
8 |
Correct |
40 ms |
5460 KB |
Output is correct |
9 |
Correct |
38 ms |
5516 KB |
Output is correct |
10 |
Correct |
32 ms |
3676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
4548 KB |
Output is correct |
2 |
Correct |
66 ms |
4444 KB |
Output is correct |
3 |
Correct |
58 ms |
4532 KB |
Output is correct |
4 |
Correct |
58 ms |
4520 KB |
Output is correct |
5 |
Correct |
58 ms |
4452 KB |
Output is correct |
6 |
Correct |
58 ms |
4420 KB |
Output is correct |
7 |
Correct |
59 ms |
4464 KB |
Output is correct |
8 |
Correct |
58 ms |
4436 KB |
Output is correct |
9 |
Correct |
59 ms |
4576 KB |
Output is correct |
10 |
Correct |
60 ms |
4512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
600 KB |
Output is correct |
23 |
Correct |
1 ms |
504 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
476 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
4068 KB |
Output is correct |
2 |
Correct |
42 ms |
4336 KB |
Output is correct |
3 |
Correct |
45 ms |
4444 KB |
Output is correct |
4 |
Correct |
44 ms |
4436 KB |
Output is correct |
5 |
Correct |
59 ms |
4428 KB |
Output is correct |
6 |
Correct |
42 ms |
4204 KB |
Output is correct |
7 |
Correct |
41 ms |
4176 KB |
Output is correct |
8 |
Correct |
42 ms |
4444 KB |
Output is correct |
9 |
Correct |
49 ms |
4176 KB |
Output is correct |
10 |
Correct |
43 ms |
4416 KB |
Output is correct |
11 |
Correct |
44 ms |
3416 KB |
Output is correct |
12 |
Correct |
32 ms |
3540 KB |
Output is correct |
13 |
Correct |
30 ms |
3420 KB |
Output is correct |
14 |
Correct |
34 ms |
3412 KB |
Output is correct |
15 |
Correct |
38 ms |
5612 KB |
Output is correct |
16 |
Correct |
31 ms |
3672 KB |
Output is correct |
17 |
Correct |
33 ms |
4108 KB |
Output is correct |
18 |
Correct |
40 ms |
5460 KB |
Output is correct |
19 |
Correct |
38 ms |
5516 KB |
Output is correct |
20 |
Correct |
32 ms |
3676 KB |
Output is correct |
21 |
Correct |
61 ms |
4548 KB |
Output is correct |
22 |
Correct |
66 ms |
4444 KB |
Output is correct |
23 |
Correct |
58 ms |
4532 KB |
Output is correct |
24 |
Correct |
58 ms |
4520 KB |
Output is correct |
25 |
Correct |
58 ms |
4452 KB |
Output is correct |
26 |
Correct |
58 ms |
4420 KB |
Output is correct |
27 |
Correct |
59 ms |
4464 KB |
Output is correct |
28 |
Correct |
58 ms |
4436 KB |
Output is correct |
29 |
Correct |
59 ms |
4576 KB |
Output is correct |
30 |
Correct |
60 ms |
4512 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
1 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
1 ms |
348 KB |
Output is correct |
50 |
Correct |
1 ms |
348 KB |
Output is correct |
51 |
Correct |
1 ms |
348 KB |
Output is correct |
52 |
Correct |
1 ms |
600 KB |
Output is correct |
53 |
Correct |
1 ms |
504 KB |
Output is correct |
54 |
Correct |
1 ms |
348 KB |
Output is correct |
55 |
Correct |
1 ms |
476 KB |
Output is correct |
56 |
Correct |
1 ms |
348 KB |
Output is correct |
57 |
Correct |
1 ms |
348 KB |
Output is correct |
58 |
Correct |
1 ms |
348 KB |
Output is correct |
59 |
Correct |
1 ms |
348 KB |
Output is correct |
60 |
Correct |
1 ms |
348 KB |
Output is correct |
61 |
Correct |
112 ms |
5724 KB |
Output is correct |
62 |
Correct |
93 ms |
5844 KB |
Output is correct |
63 |
Correct |
70 ms |
5700 KB |
Output is correct |
64 |
Correct |
100 ms |
5712 KB |
Output is correct |
65 |
Correct |
99 ms |
5724 KB |
Output is correct |
66 |
Correct |
97 ms |
5792 KB |
Output is correct |
67 |
Correct |
96 ms |
5712 KB |
Output is correct |
68 |
Correct |
64 ms |
5876 KB |
Output is correct |
69 |
Correct |
58 ms |
5708 KB |
Output is correct |
70 |
Correct |
62 ms |
5676 KB |
Output is correct |