# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
791497 |
2023-07-24T07:03:34 Z |
adaawf |
Feast (NOI19_feast) |
C++14 |
|
94 ms |
5752 KB |
#include <iostream>
#include <cstring>
using namespace std;
long long int a[500005], c[500005], f[305][305];
int main() {
memset(f, 0, sizeof f);
int n, k, flag = 0, h = 0;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] < 0) {
flag++;
h = i;
}
c[i] = c[i - 1] + a[i];
}
if (flag == 0) {
cout << c[n];
return 0;
}
if (flag == 1) {
if (k >= 2) {
cout << c[n] - a[h];
}
else {
cout << max(c[h - 1], max(c[n] - c[h], c[n]));
}
return 0;
}
if (k == 1) {
long long int mi = 0, ma = 0;
for (int i = 1; i <= n; i++) {
mi = min(mi, c[i]);
ma = max(ma, c[i] - mi);
}
cout << ma;
return 0;
}
if (n <= 300 && k <= 300) {
f[0][0] = 0;
for (int i = 1; i <= n; i++) {
f[i][0] = 0;
for (int j = 1; j <= k; j++) {
f[i][j] = f[i - 1][j];
for (int g = i; g >= 1; g--) {
f[i][j] = max(f[i][j], f[g - 1][j - 1] + c[i] - c[g - 1]);
}
}
}
long long int ma = 0;
for (int i = 0; i <= k; i++) {
ma = max(ma, f[n][i]);
}
cout << ma;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
5604 KB |
Output is correct |
2 |
Correct |
80 ms |
5548 KB |
Output is correct |
3 |
Correct |
82 ms |
5708 KB |
Output is correct |
4 |
Correct |
80 ms |
5676 KB |
Output is correct |
5 |
Correct |
80 ms |
5560 KB |
Output is correct |
6 |
Correct |
82 ms |
5584 KB |
Output is correct |
7 |
Correct |
82 ms |
5596 KB |
Output is correct |
8 |
Correct |
82 ms |
5580 KB |
Output is correct |
9 |
Correct |
81 ms |
5532 KB |
Output is correct |
10 |
Correct |
80 ms |
5524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
5580 KB |
Output is correct |
2 |
Correct |
42 ms |
5636 KB |
Output is correct |
3 |
Correct |
42 ms |
5488 KB |
Output is correct |
4 |
Correct |
42 ms |
5584 KB |
Output is correct |
5 |
Correct |
79 ms |
5468 KB |
Output is correct |
6 |
Correct |
48 ms |
5584 KB |
Output is correct |
7 |
Correct |
44 ms |
5644 KB |
Output is correct |
8 |
Correct |
82 ms |
5636 KB |
Output is correct |
9 |
Correct |
85 ms |
5460 KB |
Output is correct |
10 |
Correct |
51 ms |
5660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
88 ms |
5628 KB |
Output is correct |
2 |
Correct |
87 ms |
5492 KB |
Output is correct |
3 |
Correct |
87 ms |
5752 KB |
Output is correct |
4 |
Correct |
87 ms |
5584 KB |
Output is correct |
5 |
Correct |
87 ms |
5636 KB |
Output is correct |
6 |
Correct |
89 ms |
5652 KB |
Output is correct |
7 |
Correct |
88 ms |
5580 KB |
Output is correct |
8 |
Correct |
87 ms |
5600 KB |
Output is correct |
9 |
Correct |
94 ms |
5608 KB |
Output is correct |
10 |
Correct |
87 ms |
5600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
968 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
940 KB |
Output is correct |
7 |
Correct |
1 ms |
980 KB |
Output is correct |
8 |
Correct |
1 ms |
980 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
968 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
940 KB |
Output is correct |
7 |
Correct |
1 ms |
980 KB |
Output is correct |
8 |
Correct |
1 ms |
980 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
980 KB |
Output is correct |
11 |
Correct |
3 ms |
980 KB |
Output is correct |
12 |
Correct |
4 ms |
980 KB |
Output is correct |
13 |
Correct |
1 ms |
980 KB |
Output is correct |
14 |
Correct |
3 ms |
980 KB |
Output is correct |
15 |
Correct |
2 ms |
980 KB |
Output is correct |
16 |
Correct |
1 ms |
980 KB |
Output is correct |
17 |
Correct |
3 ms |
980 KB |
Output is correct |
18 |
Correct |
1 ms |
980 KB |
Output is correct |
19 |
Correct |
1 ms |
980 KB |
Output is correct |
20 |
Correct |
1 ms |
980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
968 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
940 KB |
Output is correct |
7 |
Correct |
1 ms |
980 KB |
Output is correct |
8 |
Correct |
1 ms |
980 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
980 KB |
Output is correct |
11 |
Correct |
3 ms |
980 KB |
Output is correct |
12 |
Correct |
4 ms |
980 KB |
Output is correct |
13 |
Correct |
1 ms |
980 KB |
Output is correct |
14 |
Correct |
3 ms |
980 KB |
Output is correct |
15 |
Correct |
2 ms |
980 KB |
Output is correct |
16 |
Correct |
1 ms |
980 KB |
Output is correct |
17 |
Correct |
3 ms |
980 KB |
Output is correct |
18 |
Correct |
1 ms |
980 KB |
Output is correct |
19 |
Correct |
1 ms |
980 KB |
Output is correct |
20 |
Correct |
1 ms |
980 KB |
Output is correct |
21 |
Incorrect |
1 ms |
980 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
5604 KB |
Output is correct |
2 |
Correct |
80 ms |
5548 KB |
Output is correct |
3 |
Correct |
82 ms |
5708 KB |
Output is correct |
4 |
Correct |
80 ms |
5676 KB |
Output is correct |
5 |
Correct |
80 ms |
5560 KB |
Output is correct |
6 |
Correct |
82 ms |
5584 KB |
Output is correct |
7 |
Correct |
82 ms |
5596 KB |
Output is correct |
8 |
Correct |
82 ms |
5580 KB |
Output is correct |
9 |
Correct |
81 ms |
5532 KB |
Output is correct |
10 |
Correct |
80 ms |
5524 KB |
Output is correct |
11 |
Correct |
42 ms |
5580 KB |
Output is correct |
12 |
Correct |
42 ms |
5636 KB |
Output is correct |
13 |
Correct |
42 ms |
5488 KB |
Output is correct |
14 |
Correct |
42 ms |
5584 KB |
Output is correct |
15 |
Correct |
79 ms |
5468 KB |
Output is correct |
16 |
Correct |
48 ms |
5584 KB |
Output is correct |
17 |
Correct |
44 ms |
5644 KB |
Output is correct |
18 |
Correct |
82 ms |
5636 KB |
Output is correct |
19 |
Correct |
85 ms |
5460 KB |
Output is correct |
20 |
Correct |
51 ms |
5660 KB |
Output is correct |
21 |
Correct |
88 ms |
5628 KB |
Output is correct |
22 |
Correct |
87 ms |
5492 KB |
Output is correct |
23 |
Correct |
87 ms |
5752 KB |
Output is correct |
24 |
Correct |
87 ms |
5584 KB |
Output is correct |
25 |
Correct |
87 ms |
5636 KB |
Output is correct |
26 |
Correct |
89 ms |
5652 KB |
Output is correct |
27 |
Correct |
88 ms |
5580 KB |
Output is correct |
28 |
Correct |
87 ms |
5600 KB |
Output is correct |
29 |
Correct |
94 ms |
5608 KB |
Output is correct |
30 |
Correct |
87 ms |
5600 KB |
Output is correct |
31 |
Correct |
1 ms |
980 KB |
Output is correct |
32 |
Correct |
1 ms |
980 KB |
Output is correct |
33 |
Correct |
1 ms |
968 KB |
Output is correct |
34 |
Correct |
1 ms |
980 KB |
Output is correct |
35 |
Correct |
1 ms |
980 KB |
Output is correct |
36 |
Correct |
1 ms |
940 KB |
Output is correct |
37 |
Correct |
1 ms |
980 KB |
Output is correct |
38 |
Correct |
1 ms |
980 KB |
Output is correct |
39 |
Correct |
1 ms |
980 KB |
Output is correct |
40 |
Correct |
1 ms |
980 KB |
Output is correct |
41 |
Correct |
3 ms |
980 KB |
Output is correct |
42 |
Correct |
4 ms |
980 KB |
Output is correct |
43 |
Correct |
1 ms |
980 KB |
Output is correct |
44 |
Correct |
3 ms |
980 KB |
Output is correct |
45 |
Correct |
2 ms |
980 KB |
Output is correct |
46 |
Correct |
1 ms |
980 KB |
Output is correct |
47 |
Correct |
3 ms |
980 KB |
Output is correct |
48 |
Correct |
1 ms |
980 KB |
Output is correct |
49 |
Correct |
1 ms |
980 KB |
Output is correct |
50 |
Correct |
1 ms |
980 KB |
Output is correct |
51 |
Incorrect |
1 ms |
980 KB |
Output isn't correct |
52 |
Halted |
0 ms |
0 KB |
- |