#include <bits/stdc++.h>
using namespace std;
const int N = 300000;
void update(pair<long long, int>& a, const pair<long long, int>& b) {
if (a.first < b.first)
a = b;
}
pair<long long, int> solve(int n, long long *pp, long long t) {
pair<long long, int> last{0, 0}, dp{0, 0};
for (int i = 0; i < n; i++) {
update(dp, make_pair(last.first + pp[i] - t, last.second + 1));
update(last, make_pair(dp.first - pp[i], dp.second));
}
return dp;
}
int main() {
int n, k;
scanf("%d%d", &n, &k);
static long long pp[N];
for (int i = 0; i < n; i++) {
int a;
scanf("%d", &a);
pp[i] = (i > 0 ? pp[i - 1] : 0) + a;
}
long long low = 0, hi = 0x3f3f3f3f3f3f3f3f;
while (low < hi) {
long long t = (low + hi) / 2;
if (solve(n, pp, t).second > k)
low = t + 1;
else
hi = t;
}
printf("%lld\n", solve(n, pp, low).first + low * k);
return 0;
}
Compilation message
feast.cpp: In function 'int main()':
feast.cpp:22:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | scanf("%d%d", &n, &k);
| ~~~~~^~~~~~~~~~~~~~~~
feast.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | scanf("%d", &a);
| ~~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
2516 KB |
Output is correct |
2 |
Correct |
54 ms |
2816 KB |
Output is correct |
3 |
Correct |
53 ms |
2884 KB |
Output is correct |
4 |
Correct |
52 ms |
2860 KB |
Output is correct |
5 |
Correct |
50 ms |
2916 KB |
Output is correct |
6 |
Correct |
64 ms |
2720 KB |
Output is correct |
7 |
Correct |
68 ms |
2716 KB |
Output is correct |
8 |
Correct |
58 ms |
2824 KB |
Output is correct |
9 |
Correct |
49 ms |
2764 KB |
Output is correct |
10 |
Correct |
57 ms |
2904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
2576 KB |
Output is correct |
2 |
Correct |
47 ms |
2540 KB |
Output is correct |
3 |
Correct |
48 ms |
2576 KB |
Output is correct |
4 |
Correct |
55 ms |
2596 KB |
Output is correct |
5 |
Correct |
56 ms |
2836 KB |
Output is correct |
6 |
Correct |
46 ms |
2768 KB |
Output is correct |
7 |
Correct |
49 ms |
2884 KB |
Output is correct |
8 |
Correct |
53 ms |
2816 KB |
Output is correct |
9 |
Correct |
51 ms |
2816 KB |
Output is correct |
10 |
Correct |
45 ms |
2848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
2560 KB |
Output is correct |
2 |
Correct |
104 ms |
2480 KB |
Output is correct |
3 |
Correct |
79 ms |
2596 KB |
Output is correct |
4 |
Correct |
77 ms |
2580 KB |
Output is correct |
5 |
Correct |
82 ms |
2600 KB |
Output is correct |
6 |
Correct |
85 ms |
2608 KB |
Output is correct |
7 |
Correct |
89 ms |
2616 KB |
Output is correct |
8 |
Correct |
82 ms |
2592 KB |
Output is correct |
9 |
Correct |
136 ms |
2628 KB |
Output is correct |
10 |
Correct |
140 ms |
2616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
308 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 |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
2 ms |
312 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
308 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 |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
2 ms |
312 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 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 |
304 KB |
Output is correct |
15 |
Correct |
0 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 |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
308 KB |
Output is correct |
20 |
Correct |
1 ms |
308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
308 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 |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
2 ms |
312 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 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 |
304 KB |
Output is correct |
15 |
Correct |
0 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 |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
308 KB |
Output is correct |
20 |
Correct |
1 ms |
308 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
2516 KB |
Output is correct |
2 |
Correct |
54 ms |
2816 KB |
Output is correct |
3 |
Correct |
53 ms |
2884 KB |
Output is correct |
4 |
Correct |
52 ms |
2860 KB |
Output is correct |
5 |
Correct |
50 ms |
2916 KB |
Output is correct |
6 |
Correct |
64 ms |
2720 KB |
Output is correct |
7 |
Correct |
68 ms |
2716 KB |
Output is correct |
8 |
Correct |
58 ms |
2824 KB |
Output is correct |
9 |
Correct |
49 ms |
2764 KB |
Output is correct |
10 |
Correct |
57 ms |
2904 KB |
Output is correct |
11 |
Correct |
55 ms |
2576 KB |
Output is correct |
12 |
Correct |
47 ms |
2540 KB |
Output is correct |
13 |
Correct |
48 ms |
2576 KB |
Output is correct |
14 |
Correct |
55 ms |
2596 KB |
Output is correct |
15 |
Correct |
56 ms |
2836 KB |
Output is correct |
16 |
Correct |
46 ms |
2768 KB |
Output is correct |
17 |
Correct |
49 ms |
2884 KB |
Output is correct |
18 |
Correct |
53 ms |
2816 KB |
Output is correct |
19 |
Correct |
51 ms |
2816 KB |
Output is correct |
20 |
Correct |
45 ms |
2848 KB |
Output is correct |
21 |
Correct |
78 ms |
2560 KB |
Output is correct |
22 |
Correct |
104 ms |
2480 KB |
Output is correct |
23 |
Correct |
79 ms |
2596 KB |
Output is correct |
24 |
Correct |
77 ms |
2580 KB |
Output is correct |
25 |
Correct |
82 ms |
2600 KB |
Output is correct |
26 |
Correct |
85 ms |
2608 KB |
Output is correct |
27 |
Correct |
89 ms |
2616 KB |
Output is correct |
28 |
Correct |
82 ms |
2592 KB |
Output is correct |
29 |
Correct |
136 ms |
2628 KB |
Output is correct |
30 |
Correct |
140 ms |
2616 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
308 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 |
312 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
2 ms |
312 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
304 KB |
Output is correct |
45 |
Correct |
0 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
256 KB |
Output is correct |
49 |
Correct |
1 ms |
308 KB |
Output is correct |
50 |
Correct |
1 ms |
308 KB |
Output is correct |
51 |
Correct |
1 ms |
340 KB |
Output is correct |
52 |
Correct |
1 ms |
340 KB |
Output is correct |
53 |
Correct |
1 ms |
340 KB |
Output is correct |
54 |
Correct |
1 ms |
384 KB |
Output is correct |
55 |
Correct |
1 ms |
340 KB |
Output is correct |
56 |
Correct |
1 ms |
340 KB |
Output is correct |
57 |
Correct |
1 ms |
340 KB |
Output is correct |
58 |
Correct |
1 ms |
340 KB |
Output is correct |
59 |
Correct |
1 ms |
340 KB |
Output is correct |
60 |
Correct |
2 ms |
340 KB |
Output is correct |
61 |
Correct |
126 ms |
5552 KB |
Output is correct |
62 |
Correct |
121 ms |
5680 KB |
Output is correct |
63 |
Correct |
94 ms |
5540 KB |
Output is correct |
64 |
Correct |
137 ms |
5644 KB |
Output is correct |
65 |
Correct |
142 ms |
5532 KB |
Output is correct |
66 |
Correct |
155 ms |
5624 KB |
Output is correct |
67 |
Correct |
122 ms |
5540 KB |
Output is correct |
68 |
Correct |
124 ms |
5648 KB |
Output is correct |
69 |
Correct |
109 ms |
5544 KB |
Output is correct |
70 |
Correct |
105 ms |
5512 KB |
Output is correct |