#include <bits/stdc++.h>
using namespace std;
const int maxn = 750;
int n, m, s;
int mchild[maxn];
int schild[maxn];
int dp[maxn][maxn][maxn];
int sol = 0;
int main(){
cin >> n >> m >> s;
for(int i = 0; i < n; i++){
cin >> mchild[i] >> schild[i];
}
for(int i = 1; i <= n; i++){
for(int j = 0; j <= m; j++){
for(int k = 0; k <= s; k++){
if(k == 0 and j == 0) continue;
dp[i][j][k] = max(dp[i-1][j][k], dp[i][j][k]);
int ssl = 0;
if(k == 0) ssl = dp[i-1][j-1][k]+mchild[i-1];
else if(j == 0) ssl = dp[i-1][j][k-1]+schild[i-1];
else ssl = max(dp[i-1][j-1][k]+mchild[i-1], dp[i-1][j][k-1]+schild[i-1]);
dp[i][j][k] = max(ssl, dp[i][j][k]);
}
}
//cout << dp[i][1][1] << '\n';
}
cout << dp[n][m][s] << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
4 ms |
8284 KB |
Output is correct |
5 |
Correct |
1 ms |
1884 KB |
Output is correct |
6 |
Correct |
11 ms |
23604 KB |
Output is correct |
7 |
Runtime error |
20 ms |
348 KB |
Execution killed with signal 11 |
8 |
Runtime error |
20 ms |
348 KB |
Execution killed with signal 11 |
9 |
Runtime error |
21 ms |
344 KB |
Execution killed with signal 11 |
10 |
Runtime error |
21 ms |
348 KB |
Execution killed with signal 11 |
11 |
Runtime error |
20 ms |
344 KB |
Execution killed with signal 11 |
12 |
Runtime error |
21 ms |
344 KB |
Execution killed with signal 11 |
13 |
Runtime error |
21 ms |
348 KB |
Execution killed with signal 11 |
14 |
Runtime error |
20 ms |
348 KB |
Execution killed with signal 11 |
15 |
Runtime error |
21 ms |
512 KB |
Execution killed with signal 11 |
16 |
Runtime error |
21 ms |
348 KB |
Execution killed with signal 11 |
17 |
Runtime error |
20 ms |
348 KB |
Execution killed with signal 11 |
18 |
Runtime error |
27 ms |
344 KB |
Execution killed with signal 11 |
19 |
Runtime error |
21 ms |
348 KB |
Execution killed with signal 11 |
20 |
Runtime error |
20 ms |
348 KB |
Execution killed with signal 11 |