#include <bits/stdc++.h>
using namespace std;
int k, n, m, a[1024], b[1024];
vector <vector <int>> dp[2];
bool p, q;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
cin >> k >> n >> m;
for (int i = 1; i <= k; i++) cin >> a[i] >> b[i];
dp[0].assign(n + 1, vector<int>(m + 1, 0));
dp[1].assign(n + 1, vector<int>(m + 1, 0));
p = 1; q = 0;
for (int i = 1; i <= k; i++) {
swap(p, q);
for (int x = 0; x <= n; x++)
for (int y = 0; y <= m; y++) {
dp[q][x][y] = dp[p][x][y];
if (x) dp[q][x][y] = max(dp[q][x][y], dp[p][x - 1][y] + a[i]);
if (y) dp[q][x][y] = max(dp[q][x][y], dp[p][x][y - 1] + b[i]);
}
}
cout << dp[q][n][m];
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
372 KB |
Output is correct |
5 |
Correct |
0 ms |
460 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
8 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
9 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
10 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
11 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
12 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
13 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
14 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
15 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
16 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
17 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
18 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
19 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
20 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |