// #cheat_when_we_are_young
// #cheatkhitacontre #khionhatoicheat
// #thaycuckythatvong
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
using namespace std;
const int NM = 2005, MN = 3e5 + 5;
int n, k, a[MN], dp[NM][NM];
void sub1() {
for (int i = 1; i <= n; ++i) a[i] += a[i-1];
cout << a[n];
}
void sub2() {
int ans = 0;
for (int i = 1; i <= n; ++i) if (a[i] >= 0) ans += a[i];
cout << ans;
}
void sub3() {
int minprefix = 0, ans = 0;
for (int i = 1; i <= n; ++i) {
a[i] += a[i-1];
minprefix = min(minprefix, a[i]);
ans = max(ans, a[i] - minprefix);
}
cout << ans;
}
void nnk() {
for (int i = 1; i <= n; ++i) a[i] += a[i-1];
for (int i = 1; i <= n; ++i) for (int j = 1; j <= k; ++j) {
dp[i][j] = max(dp[i][j], dp[i-1][j]);
for (int p = 0; p < i; ++p) dp[i][j] = max(dp[i][j], dp[p][j-1] + a[i] - a[p]);
}
cout << dp[n][k];
}
signed main() {
IOS;
cin >> n >> k;
int check = 0;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
if (a[i] < 0) ++check;
}
if (check == 0) {
sub1();
return 0;
}
if (k == 1) {
sub3();
return 0;
}
if (check == 1) {
sub2();
return 0;
}
nnk();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
2516 KB |
Output is correct |
2 |
Correct |
22 ms |
2552 KB |
Output is correct |
3 |
Correct |
23 ms |
2660 KB |
Output is correct |
4 |
Correct |
24 ms |
2664 KB |
Output is correct |
5 |
Correct |
29 ms |
2644 KB |
Output is correct |
6 |
Correct |
22 ms |
2568 KB |
Output is correct |
7 |
Correct |
22 ms |
2608 KB |
Output is correct |
8 |
Correct |
22 ms |
2572 KB |
Output is correct |
9 |
Correct |
22 ms |
2516 KB |
Output is correct |
10 |
Correct |
28 ms |
2508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
2584 KB |
Output is correct |
2 |
Correct |
16 ms |
3796 KB |
Output is correct |
3 |
Correct |
16 ms |
3652 KB |
Output is correct |
4 |
Correct |
16 ms |
3648 KB |
Output is correct |
5 |
Correct |
27 ms |
3760 KB |
Output is correct |
6 |
Correct |
20 ms |
3668 KB |
Output is correct |
7 |
Correct |
15 ms |
3744 KB |
Output is correct |
8 |
Correct |
25 ms |
3924 KB |
Output is correct |
9 |
Correct |
25 ms |
3792 KB |
Output is correct |
10 |
Correct |
15 ms |
3796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
2636 KB |
Output is correct |
2 |
Correct |
24 ms |
2484 KB |
Output is correct |
3 |
Correct |
24 ms |
2644 KB |
Output is correct |
4 |
Correct |
24 ms |
2604 KB |
Output is correct |
5 |
Correct |
25 ms |
2584 KB |
Output is correct |
6 |
Correct |
27 ms |
2604 KB |
Output is correct |
7 |
Correct |
27 ms |
2676 KB |
Output is correct |
8 |
Correct |
25 ms |
2644 KB |
Output is correct |
9 |
Correct |
26 ms |
2636 KB |
Output is correct |
10 |
Correct |
25 ms |
2604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
0 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
0 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
0 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
0 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
596 KB |
Output is correct |
11 |
Correct |
3 ms |
1620 KB |
Output is correct |
12 |
Correct |
3 ms |
1492 KB |
Output is correct |
13 |
Correct |
2 ms |
1364 KB |
Output is correct |
14 |
Correct |
5 ms |
1488 KB |
Output is correct |
15 |
Correct |
2 ms |
1444 KB |
Output is correct |
16 |
Correct |
3 ms |
1364 KB |
Output is correct |
17 |
Correct |
5 ms |
1492 KB |
Output is correct |
18 |
Correct |
1 ms |
1364 KB |
Output is correct |
19 |
Correct |
1 ms |
1364 KB |
Output is correct |
20 |
Correct |
1 ms |
1492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
0 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
0 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
596 KB |
Output is correct |
11 |
Correct |
3 ms |
1620 KB |
Output is correct |
12 |
Correct |
3 ms |
1492 KB |
Output is correct |
13 |
Correct |
2 ms |
1364 KB |
Output is correct |
14 |
Correct |
5 ms |
1488 KB |
Output is correct |
15 |
Correct |
2 ms |
1444 KB |
Output is correct |
16 |
Correct |
3 ms |
1364 KB |
Output is correct |
17 |
Correct |
5 ms |
1492 KB |
Output is correct |
18 |
Correct |
1 ms |
1364 KB |
Output is correct |
19 |
Correct |
1 ms |
1364 KB |
Output is correct |
20 |
Correct |
1 ms |
1492 KB |
Output is correct |
21 |
Correct |
793 ms |
11060 KB |
Output is correct |
22 |
Execution timed out |
1083 ms |
15928 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
2516 KB |
Output is correct |
2 |
Correct |
22 ms |
2552 KB |
Output is correct |
3 |
Correct |
23 ms |
2660 KB |
Output is correct |
4 |
Correct |
24 ms |
2664 KB |
Output is correct |
5 |
Correct |
29 ms |
2644 KB |
Output is correct |
6 |
Correct |
22 ms |
2568 KB |
Output is correct |
7 |
Correct |
22 ms |
2608 KB |
Output is correct |
8 |
Correct |
22 ms |
2572 KB |
Output is correct |
9 |
Correct |
22 ms |
2516 KB |
Output is correct |
10 |
Correct |
28 ms |
2508 KB |
Output is correct |
11 |
Correct |
15 ms |
2584 KB |
Output is correct |
12 |
Correct |
16 ms |
3796 KB |
Output is correct |
13 |
Correct |
16 ms |
3652 KB |
Output is correct |
14 |
Correct |
16 ms |
3648 KB |
Output is correct |
15 |
Correct |
27 ms |
3760 KB |
Output is correct |
16 |
Correct |
20 ms |
3668 KB |
Output is correct |
17 |
Correct |
15 ms |
3744 KB |
Output is correct |
18 |
Correct |
25 ms |
3924 KB |
Output is correct |
19 |
Correct |
25 ms |
3792 KB |
Output is correct |
20 |
Correct |
15 ms |
3796 KB |
Output is correct |
21 |
Correct |
25 ms |
2636 KB |
Output is correct |
22 |
Correct |
24 ms |
2484 KB |
Output is correct |
23 |
Correct |
24 ms |
2644 KB |
Output is correct |
24 |
Correct |
24 ms |
2604 KB |
Output is correct |
25 |
Correct |
25 ms |
2584 KB |
Output is correct |
26 |
Correct |
27 ms |
2604 KB |
Output is correct |
27 |
Correct |
27 ms |
2676 KB |
Output is correct |
28 |
Correct |
25 ms |
2644 KB |
Output is correct |
29 |
Correct |
26 ms |
2636 KB |
Output is correct |
30 |
Correct |
25 ms |
2604 KB |
Output is correct |
31 |
Correct |
0 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
596 KB |
Output is correct |
33 |
Correct |
0 ms |
596 KB |
Output is correct |
34 |
Correct |
1 ms |
596 KB |
Output is correct |
35 |
Correct |
0 ms |
596 KB |
Output is correct |
36 |
Correct |
1 ms |
596 KB |
Output is correct |
37 |
Correct |
1 ms |
596 KB |
Output is correct |
38 |
Correct |
1 ms |
596 KB |
Output is correct |
39 |
Correct |
0 ms |
340 KB |
Output is correct |
40 |
Correct |
0 ms |
596 KB |
Output is correct |
41 |
Correct |
3 ms |
1620 KB |
Output is correct |
42 |
Correct |
3 ms |
1492 KB |
Output is correct |
43 |
Correct |
2 ms |
1364 KB |
Output is correct |
44 |
Correct |
5 ms |
1488 KB |
Output is correct |
45 |
Correct |
2 ms |
1444 KB |
Output is correct |
46 |
Correct |
3 ms |
1364 KB |
Output is correct |
47 |
Correct |
5 ms |
1492 KB |
Output is correct |
48 |
Correct |
1 ms |
1364 KB |
Output is correct |
49 |
Correct |
1 ms |
1364 KB |
Output is correct |
50 |
Correct |
1 ms |
1492 KB |
Output is correct |
51 |
Correct |
793 ms |
11060 KB |
Output is correct |
52 |
Execution timed out |
1083 ms |
15928 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |