# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
674618 |
2022-12-25T12:24:42 Z |
stevancv |
Feast (NOI19_feast) |
C++14 |
|
239 ms |
13940 KB |
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 3e5 + 2;
const int mod = 1e9 + 7;
ll a[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[i] += a[i - 1];
}
auto Can = [&] (ll penalty) {
vector<ll> dp(n + 1);
vector<int> cnt(n + 1);
vector<pair<ll, int>> p(n + 1);
p[0] = {0, 0};
for (int i = 1; i <= n; i++) {
dp[i] = dp[i - 1];
cnt[i] = cnt[i - 1];
p[i] = p[i - 1];
if (-a[i] > p[i].first) p[i] = {-a[i], i};
if (dp[i] < p[i].first + penalty + a[i]) {
dp[i] = p[i].first + penalty + a[i];
cnt[i] = cnt[p[i].second] + 1;
}
if (dp[i] - a[i] > p[i].first) p[i] = {dp[i] - a[i], i};
}
if (cnt[n] > m) return (ll)-1e18;
return dp[n] - (ll) cnt[n] * penalty;
};
ll l = -1e18, r = 0, ans = 0;
while (l <= r) {
ll penalty = l + r >> 1;
if (Can(penalty) != -1e18) {
ans = penalty;
l = penalty + 1;
}
else r = penalty - 1;
}
ll o = Can(ans);
if (o < 0) o = 0;
cout << o << en;
return 0;
}
Compilation message
feast.cpp: In function 'int main()':
feast.cpp:43:24: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
43 | ll penalty = l + r >> 1;
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
133 ms |
13340 KB |
Output is correct |
2 |
Correct |
149 ms |
13600 KB |
Output is correct |
3 |
Correct |
141 ms |
13760 KB |
Output is correct |
4 |
Correct |
140 ms |
13680 KB |
Output is correct |
5 |
Correct |
133 ms |
13616 KB |
Output is correct |
6 |
Correct |
135 ms |
13368 KB |
Output is correct |
7 |
Correct |
125 ms |
13356 KB |
Output is correct |
8 |
Correct |
158 ms |
13628 KB |
Output is correct |
9 |
Correct |
133 ms |
13396 KB |
Output is correct |
10 |
Correct |
120 ms |
13500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
129 ms |
11732 KB |
Output is correct |
2 |
Correct |
130 ms |
11992 KB |
Output is correct |
3 |
Correct |
116 ms |
11716 KB |
Output is correct |
4 |
Correct |
111 ms |
11820 KB |
Output is correct |
5 |
Correct |
124 ms |
13360 KB |
Output is correct |
6 |
Correct |
113 ms |
11708 KB |
Output is correct |
7 |
Correct |
132 ms |
11980 KB |
Output is correct |
8 |
Correct |
123 ms |
13700 KB |
Output is correct |
9 |
Correct |
115 ms |
13328 KB |
Output is correct |
10 |
Correct |
138 ms |
11956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
143 ms |
13784 KB |
Output is correct |
2 |
Correct |
140 ms |
13736 KB |
Output is correct |
3 |
Correct |
149 ms |
13752 KB |
Output is correct |
4 |
Correct |
143 ms |
13632 KB |
Output is correct |
5 |
Correct |
140 ms |
13736 KB |
Output is correct |
6 |
Correct |
146 ms |
13824 KB |
Output is correct |
7 |
Correct |
180 ms |
13876 KB |
Output is correct |
8 |
Correct |
148 ms |
13740 KB |
Output is correct |
9 |
Correct |
147 ms |
13940 KB |
Output is correct |
10 |
Correct |
168 ms |
13792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
328 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 |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
328 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 |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
328 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
328 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
328 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 |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
328 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
328 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
2 ms |
416 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
3 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
352 KB |
Output is correct |
29 |
Correct |
2 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
133 ms |
13340 KB |
Output is correct |
2 |
Correct |
149 ms |
13600 KB |
Output is correct |
3 |
Correct |
141 ms |
13760 KB |
Output is correct |
4 |
Correct |
140 ms |
13680 KB |
Output is correct |
5 |
Correct |
133 ms |
13616 KB |
Output is correct |
6 |
Correct |
135 ms |
13368 KB |
Output is correct |
7 |
Correct |
125 ms |
13356 KB |
Output is correct |
8 |
Correct |
158 ms |
13628 KB |
Output is correct |
9 |
Correct |
133 ms |
13396 KB |
Output is correct |
10 |
Correct |
120 ms |
13500 KB |
Output is correct |
11 |
Correct |
129 ms |
11732 KB |
Output is correct |
12 |
Correct |
130 ms |
11992 KB |
Output is correct |
13 |
Correct |
116 ms |
11716 KB |
Output is correct |
14 |
Correct |
111 ms |
11820 KB |
Output is correct |
15 |
Correct |
124 ms |
13360 KB |
Output is correct |
16 |
Correct |
113 ms |
11708 KB |
Output is correct |
17 |
Correct |
132 ms |
11980 KB |
Output is correct |
18 |
Correct |
123 ms |
13700 KB |
Output is correct |
19 |
Correct |
115 ms |
13328 KB |
Output is correct |
20 |
Correct |
138 ms |
11956 KB |
Output is correct |
21 |
Correct |
143 ms |
13784 KB |
Output is correct |
22 |
Correct |
140 ms |
13736 KB |
Output is correct |
23 |
Correct |
149 ms |
13752 KB |
Output is correct |
24 |
Correct |
143 ms |
13632 KB |
Output is correct |
25 |
Correct |
140 ms |
13736 KB |
Output is correct |
26 |
Correct |
146 ms |
13824 KB |
Output is correct |
27 |
Correct |
180 ms |
13876 KB |
Output is correct |
28 |
Correct |
148 ms |
13740 KB |
Output is correct |
29 |
Correct |
147 ms |
13940 KB |
Output is correct |
30 |
Correct |
168 ms |
13792 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
328 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
328 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
324 KB |
Output is correct |
41 |
Correct |
1 ms |
340 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
1 ms |
328 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
328 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
2 ms |
416 KB |
Output is correct |
52 |
Correct |
2 ms |
340 KB |
Output is correct |
53 |
Correct |
2 ms |
340 KB |
Output is correct |
54 |
Correct |
2 ms |
340 KB |
Output is correct |
55 |
Correct |
3 ms |
340 KB |
Output is correct |
56 |
Correct |
2 ms |
340 KB |
Output is correct |
57 |
Correct |
2 ms |
340 KB |
Output is correct |
58 |
Correct |
2 ms |
352 KB |
Output is correct |
59 |
Correct |
2 ms |
340 KB |
Output is correct |
60 |
Correct |
1 ms |
340 KB |
Output is correct |
61 |
Correct |
207 ms |
13604 KB |
Output is correct |
62 |
Correct |
239 ms |
13940 KB |
Output is correct |
63 |
Correct |
179 ms |
13556 KB |
Output is correct |
64 |
Correct |
208 ms |
13828 KB |
Output is correct |
65 |
Correct |
215 ms |
13816 KB |
Output is correct |
66 |
Correct |
217 ms |
13780 KB |
Output is correct |
67 |
Correct |
213 ms |
13580 KB |
Output is correct |
68 |
Correct |
167 ms |
13788 KB |
Output is correct |
69 |
Correct |
179 ms |
13572 KB |
Output is correct |
70 |
Correct |
158 ms |
13484 KB |
Output is correct |