#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000;
const int K = MAXN * MAXN / 4;
int m, L, a[MAXN];
int dp[MAXN][MAXN * MAXN / 2];
int main(){
cin >> m >> L;
for(int i = 0; i < 2 * m + 1; ++i) cin >> a[i];
for(int i = 0; i < 2 * m + 1; ++i){
// dp[i][j] = max{dp[i - 1][j - x * (i - m)] + x}
for(int j = 0; j < MAXN * MAXN / 2; ++j){
dp[i][j] = -1e9;
for(int x = 0; x <= a[i]; ++x){
if(j - x * (i - m) >= 0){
if(i) dp[i][j] = max(dp[i][j], dp[i - 1][j - x * (i - m)] + x);
else if(j - x * (i - m) == K) dp[i][j] = max(dp[i][j], x);
}
}
}
}
if(dp[2 * m][L + K] < 0) cout << "impossible\n";
else cout << dp[2 * m][L + K];
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
10084 KB |
Output is correct |
2 |
Correct |
14 ms |
13976 KB |
Output is correct |
3 |
Correct |
9 ms |
6100 KB |
Output is correct |
4 |
Correct |
72 ms |
41296 KB |
Output is correct |
5 |
Runtime error |
332 ms |
400996 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
10084 KB |
Output is correct |
2 |
Correct |
14 ms |
13976 KB |
Output is correct |
3 |
Correct |
9 ms |
6100 KB |
Output is correct |
4 |
Correct |
72 ms |
41296 KB |
Output is correct |
5 |
Runtime error |
332 ms |
400996 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
41292 KB |
Output is correct |
2 |
Runtime error |
201 ms |
242364 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
41292 KB |
Output is correct |
2 |
Runtime error |
201 ms |
242364 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
41292 KB |
Output is correct |
2 |
Runtime error |
201 ms |
242364 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
10084 KB |
Output is correct |
2 |
Correct |
14 ms |
13976 KB |
Output is correct |
3 |
Correct |
9 ms |
6100 KB |
Output is correct |
4 |
Correct |
72 ms |
41296 KB |
Output is correct |
5 |
Runtime error |
332 ms |
400996 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
41292 KB |
Output is correct |
2 |
Runtime error |
201 ms |
242364 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
10084 KB |
Output is correct |
2 |
Correct |
14 ms |
13976 KB |
Output is correct |
3 |
Correct |
9 ms |
6100 KB |
Output is correct |
4 |
Correct |
72 ms |
41296 KB |
Output is correct |
5 |
Runtime error |
332 ms |
400996 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
41292 KB |
Output is correct |
2 |
Runtime error |
201 ms |
242364 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
10084 KB |
Output is correct |
2 |
Correct |
14 ms |
13976 KB |
Output is correct |
3 |
Correct |
9 ms |
6100 KB |
Output is correct |
4 |
Correct |
72 ms |
41296 KB |
Output is correct |
5 |
Runtime error |
332 ms |
400996 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |