# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
990890 | Celebi_276 | Schools (IZhO13_school) | C++17 | 2 ms | 604 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|---|---|---|---|
Fetching results... |