#include "bits/stdc++.h"
using namespace std;
template<typename T>
using V = vector<T>;
using ll = long long;
#define ckmax(a,b) a= max(a,b)
ll solve(V<ll>&arr, ll k, ll p) {
V<V<V<ll>>> dp(arr.size() + 1, V<V<ll>>(k + 1, V<ll>(2, -1e18)));
dp[0][0][1] = 0;
for (ll i = 1; i <= arr.size(); ++i) {
dp[i][0][1] = 0;
for (ll j = 1; j <= k; ++j) {
for (ll l = 0; l < 2; ++l) {
dp[i][j][l] = max(dp[i - 1][j - 1][1], dp[i - 1][j][1]);
if (l == 0) ckmax(dp[i][j][l], dp[i - 1][j][0]);
ckmax(dp[i][j][l], dp[i - 1][j - 1][0]);
if (l == 1) dp[i][j][l] += arr[i - 1];
}
}
}
return max(dp[arr.size()][k][0], dp[arr.size()][k][1]);
}
int main() {
ll n, k; cin >> n >> k;
V<ll> arr(n);
for (ll i = 0; i < n; ++i) {
cin >> arr[i];
}
cout << solve(arr,k,1);
}
Compilation message
feast.cpp: In function 'll solve(V<long long int>&, ll, ll)':
feast.cpp:13:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int, std::allocator<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | for (ll i = 1; i <= arr.size(); ++i) {
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
241 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
47348 KB |
Output is correct |
2 |
Correct |
87 ms |
48212 KB |
Output is correct |
3 |
Correct |
100 ms |
47188 KB |
Output is correct |
4 |
Runtime error |
217 ms |
262144 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
131 ms |
49320 KB |
Output is correct |
2 |
Correct |
124 ms |
49236 KB |
Output is correct |
3 |
Correct |
122 ms |
49488 KB |
Output is correct |
4 |
Correct |
130 ms |
49256 KB |
Output is correct |
5 |
Correct |
126 ms |
49712 KB |
Output is correct |
6 |
Correct |
125 ms |
49964 KB |
Output is correct |
7 |
Correct |
125 ms |
50104 KB |
Output is correct |
8 |
Correct |
137 ms |
49492 KB |
Output is correct |
9 |
Correct |
130 ms |
50340 KB |
Output is correct |
10 |
Correct |
131 ms |
49976 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
432 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 |
0 ms |
436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
432 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 |
0 ms |
436 KB |
Output is correct |
11 |
Correct |
1 ms |
856 KB |
Output is correct |
12 |
Correct |
1 ms |
1372 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
1116 KB |
Output is correct |
15 |
Correct |
1 ms |
860 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
1116 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
432 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 |
0 ms |
436 KB |
Output is correct |
11 |
Correct |
1 ms |
856 KB |
Output is correct |
12 |
Correct |
1 ms |
1372 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
1116 KB |
Output is correct |
15 |
Correct |
1 ms |
860 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
1116 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
28 ms |
21852 KB |
Output is correct |
22 |
Correct |
171 ms |
179324 KB |
Output is correct |
23 |
Correct |
46 ms |
41564 KB |
Output is correct |
24 |
Correct |
24 ms |
23644 KB |
Output is correct |
25 |
Correct |
35 ms |
32604 KB |
Output is correct |
26 |
Correct |
19 ms |
19544 KB |
Output is correct |
27 |
Correct |
33 ms |
30812 KB |
Output is correct |
28 |
Correct |
5 ms |
3932 KB |
Output is correct |
29 |
Correct |
4 ms |
3676 KB |
Output is correct |
30 |
Correct |
1 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
241 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |