#include <bits/stdc++.h>
#define int long long
#define N 300005
#define pb push_back
#define mod 1000000007
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int,int>
#define INF 1e18
#define FOR(i, a, b) for(int i = a; i <= b; ++i)
#define FORD(i, a, b) for(int i = a; i >= b; --i)
using namespace std;
int n, k, a[N], pre[N], dp[5500][5500];
void proc()
{
cin >> n >> k;
FOR(i, 1, n) cin >> a[i];
FOR(i, 1, n) pre[i] = pre[i - 1] + a[i];
FOR(i, 1, k)
{
int mx = -INF;
FOR(j, 1, n)
{
mx = max(mx, dp[j - 1][i - 1] - pre[j - 1]);
dp[j][i] = max(dp[j - 1][i], mx + pre[j]);
}
}
cout << dp[n][k];
}
int32_t main() {
if(fopen("test.inp", "r"))
{
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T; T = 1;
//cin >> T;
while (T--) proc();
}
Compilation message
feast.cpp: In function 'int32_t main()':
feast.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
41 | freopen("test.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
feast.cpp:42:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | freopen("test.out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
410 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
377 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
488 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6480 KB |
Output is correct |
2 |
Correct |
2 ms |
6480 KB |
Output is correct |
3 |
Correct |
1 ms |
6480 KB |
Output is correct |
4 |
Correct |
1 ms |
6480 KB |
Output is correct |
5 |
Correct |
2 ms |
6616 KB |
Output is correct |
6 |
Correct |
1 ms |
6480 KB |
Output is correct |
7 |
Correct |
1 ms |
6480 KB |
Output is correct |
8 |
Correct |
2 ms |
6480 KB |
Output is correct |
9 |
Correct |
1 ms |
6480 KB |
Output is correct |
10 |
Correct |
2 ms |
6480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6480 KB |
Output is correct |
2 |
Correct |
2 ms |
6480 KB |
Output is correct |
3 |
Correct |
1 ms |
6480 KB |
Output is correct |
4 |
Correct |
1 ms |
6480 KB |
Output is correct |
5 |
Correct |
2 ms |
6616 KB |
Output is correct |
6 |
Correct |
1 ms |
6480 KB |
Output is correct |
7 |
Correct |
1 ms |
6480 KB |
Output is correct |
8 |
Correct |
2 ms |
6480 KB |
Output is correct |
9 |
Correct |
1 ms |
6480 KB |
Output is correct |
10 |
Correct |
2 ms |
6480 KB |
Output is correct |
11 |
Correct |
3 ms |
16720 KB |
Output is correct |
12 |
Correct |
2 ms |
14672 KB |
Output is correct |
13 |
Correct |
2 ms |
14672 KB |
Output is correct |
14 |
Correct |
3 ms |
14672 KB |
Output is correct |
15 |
Correct |
2 ms |
14672 KB |
Output is correct |
16 |
Correct |
2 ms |
14672 KB |
Output is correct |
17 |
Correct |
2 ms |
14672 KB |
Output is correct |
18 |
Correct |
2 ms |
14672 KB |
Output is correct |
19 |
Correct |
2 ms |
14672 KB |
Output is correct |
20 |
Correct |
3 ms |
16720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6480 KB |
Output is correct |
2 |
Correct |
2 ms |
6480 KB |
Output is correct |
3 |
Correct |
1 ms |
6480 KB |
Output is correct |
4 |
Correct |
1 ms |
6480 KB |
Output is correct |
5 |
Correct |
2 ms |
6616 KB |
Output is correct |
6 |
Correct |
1 ms |
6480 KB |
Output is correct |
7 |
Correct |
1 ms |
6480 KB |
Output is correct |
8 |
Correct |
2 ms |
6480 KB |
Output is correct |
9 |
Correct |
1 ms |
6480 KB |
Output is correct |
10 |
Correct |
2 ms |
6480 KB |
Output is correct |
11 |
Correct |
3 ms |
16720 KB |
Output is correct |
12 |
Correct |
2 ms |
14672 KB |
Output is correct |
13 |
Correct |
2 ms |
14672 KB |
Output is correct |
14 |
Correct |
3 ms |
14672 KB |
Output is correct |
15 |
Correct |
2 ms |
14672 KB |
Output is correct |
16 |
Correct |
2 ms |
14672 KB |
Output is correct |
17 |
Correct |
2 ms |
14672 KB |
Output is correct |
18 |
Correct |
2 ms |
14672 KB |
Output is correct |
19 |
Correct |
2 ms |
14672 KB |
Output is correct |
20 |
Correct |
3 ms |
16720 KB |
Output is correct |
21 |
Correct |
11 ms |
86560 KB |
Output is correct |
22 |
Correct |
18 ms |
86608 KB |
Output is correct |
23 |
Correct |
12 ms |
86608 KB |
Output is correct |
24 |
Correct |
11 ms |
86608 KB |
Output is correct |
25 |
Correct |
11 ms |
88656 KB |
Output is correct |
26 |
Correct |
11 ms |
88732 KB |
Output is correct |
27 |
Correct |
11 ms |
88824 KB |
Output is correct |
28 |
Correct |
10 ms |
88656 KB |
Output is correct |
29 |
Correct |
9 ms |
88656 KB |
Output is correct |
30 |
Correct |
9 ms |
86660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
410 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |