#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e15 + 15;
void maximize(long long& x, long long y) {
x = max(x, y);
}
int main() {
int n, k;
cin >> n >> k;
vector<int> c(n), s(n);
for (int i = 0; i < n; ++i) {
cin >> c[i];
}
for (int i = 0; i < n; ++i) {
cin >> s[i];
}
vector<vector<vector<long long>>> dp(n, vector<vector<long long>> (3, vector<long long> (k + 1, -INF)));
dp[0][0][0] = 0;
dp[0][1][1] = s[0] - c[0];
if (k == 1) {
dp[0][2][1] = s[0] - c[0];
}
for (int i = 1; i < n; ++i) {
for (int st = 0; st < 3; ++st) {
if (st == 0) {
maximize(dp[i][0][0], dp[i - 1][0][0]);
maximize(dp[i][1][1], dp[i - 1][0][0] + s[i] - c[i]);
} else if (st == 1) {
for (int j = 1; j < k; ++j) {
maximize(dp[i][1][j], dp[i - 1][1][j] - c[i]);
maximize(dp[i][1][j], dp[i - 1][1][j - 1] + s[i] - c[i]);
}
maximize(dp[i][2][k], dp[i - 1][1][k - 1] + s[i] - c[i]);
} else {
maximize(dp[i][2][k], dp[i - 1][2][k]);
}
}
}
cout << dp[n - 1][2][k] << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
344 KB |
Partially correct |
2 |
Partially correct |
1 ms |
344 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
348 KB |
Partially correct |
2 |
Partially correct |
1 ms |
344 KB |
Partially correct |
3 |
Partially correct |
1 ms |
348 KB |
Partially correct |
4 |
Partially correct |
1 ms |
856 KB |
Partially correct |
5 |
Partially correct |
1 ms |
1372 KB |
Partially correct |
6 |
Partially correct |
1 ms |
348 KB |
Partially correct |
7 |
Partially correct |
1 ms |
604 KB |
Partially correct |
8 |
Partially correct |
1 ms |
860 KB |
Partially correct |
9 |
Partially correct |
0 ms |
604 KB |
Partially correct |
10 |
Partially correct |
0 ms |
604 KB |
Partially correct |
11 |
Partially correct |
0 ms |
604 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
348 KB |
Partially correct |
2 |
Partially correct |
1 ms |
344 KB |
Partially correct |
3 |
Partially correct |
1 ms |
348 KB |
Partially correct |
4 |
Partially correct |
1 ms |
856 KB |
Partially correct |
5 |
Partially correct |
1 ms |
1372 KB |
Partially correct |
6 |
Partially correct |
1 ms |
348 KB |
Partially correct |
7 |
Partially correct |
1 ms |
604 KB |
Partially correct |
8 |
Partially correct |
1 ms |
860 KB |
Partially correct |
9 |
Partially correct |
0 ms |
604 KB |
Partially correct |
10 |
Partially correct |
0 ms |
604 KB |
Partially correct |
11 |
Partially correct |
0 ms |
604 KB |
Partially correct |
12 |
Partially correct |
0 ms |
344 KB |
Partially correct |
13 |
Partially correct |
0 ms |
348 KB |
Partially correct |
14 |
Partially correct |
0 ms |
348 KB |
Partially correct |
15 |
Partially correct |
1 ms |
860 KB |
Partially correct |
16 |
Partially correct |
1 ms |
1368 KB |
Partially correct |
17 |
Partially correct |
0 ms |
348 KB |
Partially correct |
18 |
Partially correct |
1 ms |
604 KB |
Partially correct |
19 |
Partially correct |
0 ms |
860 KB |
Partially correct |
20 |
Partially correct |
1 ms |
600 KB |
Partially correct |
21 |
Partially correct |
1 ms |
604 KB |
Partially correct |
22 |
Partially correct |
0 ms |
604 KB |
Partially correct |
23 |
Partially correct |
426 ms |
846988 KB |
Partially correct |
24 |
Partially correct |
5 ms |
1880 KB |
Partially correct |
25 |
Partially correct |
60 ms |
142164 KB |
Partially correct |
26 |
Partially correct |
15 ms |
15324 KB |
Partially correct |
27 |
Partially correct |
189 ms |
363948 KB |
Partially correct |
28 |
Partially correct |
2 ms |
1628 KB |
Partially correct |
29 |
Partially correct |
189 ms |
424096 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
348 KB |
Partially correct |
2 |
Partially correct |
81 ms |
51280 KB |
Partially correct |
3 |
Partially correct |
127 ms |
51296 KB |
Partially correct |
4 |
Partially correct |
136 ms |
51280 KB |
Partially correct |
5 |
Partially correct |
161 ms |
51280 KB |
Partially correct |
6 |
Partially correct |
154 ms |
51276 KB |
Partially correct |
7 |
Partially correct |
122 ms |
51280 KB |
Partially correct |
8 |
Partially correct |
158 ms |
51280 KB |
Partially correct |
9 |
Partially correct |
103 ms |
51296 KB |
Partially correct |
10 |
Partially correct |
148 ms |
51276 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
348 KB |
Partially correct |
2 |
Partially correct |
81 ms |
51280 KB |
Partially correct |
3 |
Partially correct |
127 ms |
51296 KB |
Partially correct |
4 |
Partially correct |
136 ms |
51280 KB |
Partially correct |
5 |
Partially correct |
161 ms |
51280 KB |
Partially correct |
6 |
Partially correct |
154 ms |
51276 KB |
Partially correct |
7 |
Partially correct |
122 ms |
51280 KB |
Partially correct |
8 |
Partially correct |
158 ms |
51280 KB |
Partially correct |
9 |
Partially correct |
103 ms |
51296 KB |
Partially correct |
10 |
Partially correct |
148 ms |
51276 KB |
Partially correct |
11 |
Partially correct |
0 ms |
344 KB |
Partially correct |
12 |
Partially correct |
88 ms |
51292 KB |
Partially correct |
13 |
Partially correct |
134 ms |
51280 KB |
Partially correct |
14 |
Partially correct |
201 ms |
51536 KB |
Partially correct |
15 |
Partially correct |
125 ms |
51280 KB |
Partially correct |
16 |
Partially correct |
131 ms |
51276 KB |
Partially correct |
17 |
Partially correct |
146 ms |
51280 KB |
Partially correct |
18 |
Partially correct |
128 ms |
51284 KB |
Partially correct |
19 |
Partially correct |
102 ms |
51292 KB |
Partially correct |
20 |
Partially correct |
115 ms |
51536 KB |
Partially correct |
21 |
Partially correct |
1 ms |
348 KB |
Partially correct |
22 |
Partially correct |
1 ms |
348 KB |
Partially correct |
23 |
Partially correct |
1 ms |
860 KB |
Partially correct |
24 |
Partially correct |
1 ms |
1368 KB |
Partially correct |
25 |
Partially correct |
0 ms |
348 KB |
Partially correct |
26 |
Partially correct |
1 ms |
600 KB |
Partially correct |
27 |
Partially correct |
1 ms |
860 KB |
Partially correct |
28 |
Partially correct |
0 ms |
600 KB |
Partially correct |
29 |
Partially correct |
0 ms |
604 KB |
Partially correct |
30 |
Partially correct |
1 ms |
604 KB |
Partially correct |
31 |
Partially correct |
781 ms |
1213516 KB |
Partially correct |
32 |
Partially correct |
175 ms |
64672 KB |
Partially correct |
33 |
Partially correct |
673 ms |
1215788 KB |
Partially correct |
34 |
Partially correct |
755 ms |
1215312 KB |
Partially correct |
35 |
Partially correct |
715 ms |
1215140 KB |
Partially correct |
36 |
Partially correct |
749 ms |
1214820 KB |
Partially correct |
37 |
Partially correct |
710 ms |
1214512 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
344 KB |
Partially correct |
2 |
Partially correct |
1 ms |
344 KB |
Partially correct |
3 |
Partially correct |
1 ms |
348 KB |
Partially correct |
4 |
Partially correct |
1 ms |
344 KB |
Partially correct |
5 |
Partially correct |
1 ms |
348 KB |
Partially correct |
6 |
Partially correct |
1 ms |
856 KB |
Partially correct |
7 |
Partially correct |
1 ms |
1372 KB |
Partially correct |
8 |
Partially correct |
1 ms |
348 KB |
Partially correct |
9 |
Partially correct |
1 ms |
604 KB |
Partially correct |
10 |
Partially correct |
1 ms |
860 KB |
Partially correct |
11 |
Partially correct |
0 ms |
604 KB |
Partially correct |
12 |
Partially correct |
0 ms |
604 KB |
Partially correct |
13 |
Partially correct |
0 ms |
604 KB |
Partially correct |
14 |
Partially correct |
0 ms |
344 KB |
Partially correct |
15 |
Partially correct |
0 ms |
348 KB |
Partially correct |
16 |
Partially correct |
0 ms |
348 KB |
Partially correct |
17 |
Partially correct |
1 ms |
860 KB |
Partially correct |
18 |
Partially correct |
1 ms |
1368 KB |
Partially correct |
19 |
Partially correct |
0 ms |
348 KB |
Partially correct |
20 |
Partially correct |
1 ms |
604 KB |
Partially correct |
21 |
Partially correct |
0 ms |
860 KB |
Partially correct |
22 |
Partially correct |
1 ms |
600 KB |
Partially correct |
23 |
Partially correct |
1 ms |
604 KB |
Partially correct |
24 |
Partially correct |
0 ms |
604 KB |
Partially correct |
25 |
Partially correct |
426 ms |
846988 KB |
Partially correct |
26 |
Partially correct |
5 ms |
1880 KB |
Partially correct |
27 |
Partially correct |
60 ms |
142164 KB |
Partially correct |
28 |
Partially correct |
15 ms |
15324 KB |
Partially correct |
29 |
Partially correct |
189 ms |
363948 KB |
Partially correct |
30 |
Partially correct |
2 ms |
1628 KB |
Partially correct |
31 |
Partially correct |
189 ms |
424096 KB |
Partially correct |
32 |
Partially correct |
0 ms |
348 KB |
Partially correct |
33 |
Partially correct |
81 ms |
51280 KB |
Partially correct |
34 |
Partially correct |
127 ms |
51296 KB |
Partially correct |
35 |
Partially correct |
136 ms |
51280 KB |
Partially correct |
36 |
Partially correct |
161 ms |
51280 KB |
Partially correct |
37 |
Partially correct |
154 ms |
51276 KB |
Partially correct |
38 |
Partially correct |
122 ms |
51280 KB |
Partially correct |
39 |
Partially correct |
158 ms |
51280 KB |
Partially correct |
40 |
Partially correct |
103 ms |
51296 KB |
Partially correct |
41 |
Partially correct |
148 ms |
51276 KB |
Partially correct |
42 |
Partially correct |
0 ms |
344 KB |
Partially correct |
43 |
Partially correct |
88 ms |
51292 KB |
Partially correct |
44 |
Partially correct |
134 ms |
51280 KB |
Partially correct |
45 |
Partially correct |
201 ms |
51536 KB |
Partially correct |
46 |
Partially correct |
125 ms |
51280 KB |
Partially correct |
47 |
Partially correct |
131 ms |
51276 KB |
Partially correct |
48 |
Partially correct |
146 ms |
51280 KB |
Partially correct |
49 |
Partially correct |
128 ms |
51284 KB |
Partially correct |
50 |
Partially correct |
102 ms |
51292 KB |
Partially correct |
51 |
Partially correct |
115 ms |
51536 KB |
Partially correct |
52 |
Partially correct |
1 ms |
348 KB |
Partially correct |
53 |
Partially correct |
1 ms |
348 KB |
Partially correct |
54 |
Partially correct |
1 ms |
860 KB |
Partially correct |
55 |
Partially correct |
1 ms |
1368 KB |
Partially correct |
56 |
Partially correct |
0 ms |
348 KB |
Partially correct |
57 |
Partially correct |
1 ms |
600 KB |
Partially correct |
58 |
Partially correct |
1 ms |
860 KB |
Partially correct |
59 |
Partially correct |
0 ms |
600 KB |
Partially correct |
60 |
Partially correct |
0 ms |
604 KB |
Partially correct |
61 |
Partially correct |
1 ms |
604 KB |
Partially correct |
62 |
Partially correct |
781 ms |
1213516 KB |
Partially correct |
63 |
Partially correct |
175 ms |
64672 KB |
Partially correct |
64 |
Partially correct |
673 ms |
1215788 KB |
Partially correct |
65 |
Partially correct |
755 ms |
1215312 KB |
Partially correct |
66 |
Partially correct |
715 ms |
1215140 KB |
Partially correct |
67 |
Partially correct |
749 ms |
1214820 KB |
Partially correct |
68 |
Partially correct |
710 ms |
1214512 KB |
Partially correct |
69 |
Partially correct |
0 ms |
344 KB |
Partially correct |
70 |
Partially correct |
86 ms |
52128 KB |
Partially correct |
71 |
Partially correct |
188 ms |
54596 KB |
Partially correct |
72 |
Partially correct |
165 ms |
54356 KB |
Partially correct |
73 |
Partially correct |
154 ms |
54096 KB |
Partially correct |
74 |
Partially correct |
128 ms |
53824 KB |
Partially correct |
75 |
Partially correct |
114 ms |
53460 KB |
Partially correct |
76 |
Partially correct |
129 ms |
54100 KB |
Partially correct |
77 |
Partially correct |
105 ms |
52684 KB |
Partially correct |
78 |
Partially correct |
177 ms |
53400 KB |
Partially correct |
79 |
Partially correct |
0 ms |
344 KB |
Partially correct |
80 |
Partially correct |
0 ms |
348 KB |
Partially correct |
81 |
Partially correct |
1 ms |
860 KB |
Partially correct |
82 |
Partially correct |
1 ms |
1372 KB |
Partially correct |
83 |
Partially correct |
0 ms |
348 KB |
Partially correct |
84 |
Partially correct |
0 ms |
604 KB |
Partially correct |
85 |
Partially correct |
1 ms |
860 KB |
Partially correct |
86 |
Partially correct |
1 ms |
600 KB |
Partially correct |
87 |
Partially correct |
0 ms |
604 KB |
Partially correct |
88 |
Partially correct |
1 ms |
604 KB |
Partially correct |
89 |
Partially correct |
746 ms |
1216828 KB |
Partially correct |
90 |
Partially correct |
174 ms |
65992 KB |
Partially correct |
91 |
Partially correct |
741 ms |
1216208 KB |
Partially correct |
92 |
Partially correct |
722 ms |
1215932 KB |
Partially correct |
93 |
Partially correct |
730 ms |
1215928 KB |
Partially correct |
94 |
Partially correct |
690 ms |
1215024 KB |
Partially correct |
95 |
Partially correct |
693 ms |
1214664 KB |
Partially correct |
96 |
Partially correct |
396 ms |
846968 KB |
Partially correct |
97 |
Partially correct |
4 ms |
1880 KB |
Partially correct |
98 |
Partially correct |
73 ms |
142152 KB |
Partially correct |
99 |
Partially correct |
9 ms |
15452 KB |
Partially correct |
100 |
Partially correct |
175 ms |
364116 KB |
Partially correct |
101 |
Partially correct |
3 ms |
1628 KB |
Partially correct |
102 |
Partially correct |
205 ms |
424268 KB |
Partially correct |
103 |
Runtime error |
1060 ms |
2097152 KB |
Execution killed with signal 9 |
104 |
Halted |
0 ms |
0 KB |
- |