#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 605;
const int MAX_W = 11005;
const int INF = 1e9 + 7;
long long A[MAX_N], dp[2][MAX_W];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int M;
long long L;
cin >> M >> L;
for(int i = -M; i <= M; i++) {
cin >> A[i + M];
}
for(int i = 0; i < MAX_W; i++) {
dp[0][i] = -INF;
}
dp[0][MAX_W / 2] = 0;
int j = 1;
for(int i = -M; i <= M; i++, j ^= 1) {
int now = j, pre = j ^ 1;
for(int j = MAX_W - 1; j >= 0; j--) {
dp[now][j] = dp[pre][j];
for(int k = 0; k <= A[i + M]; k++) {
if(j - k * i >= 0 and j - k * i < MAX_W and dp[pre][j - k * i] != -INF) {
dp[now][j] = max(dp[now][j], dp[pre][j - k * i] + k);
}
}
}
}
if(dp[j ^ 1][MAX_W / 2 + L] == -INF) {
cout << "impossible";
}
else {
cout << dp[j ^ 1][MAX_W / 2 + L];
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Runtime error |
58 ms |
748 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Runtime error |
58 ms |
748 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
500 KB |
Output is correct |
2 |
Runtime error |
990 ms |
728 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
500 KB |
Output is correct |
2 |
Runtime error |
990 ms |
728 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
500 KB |
Output is correct |
2 |
Runtime error |
990 ms |
728 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Runtime error |
58 ms |
748 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
500 KB |
Output is correct |
2 |
Runtime error |
990 ms |
728 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Runtime error |
58 ms |
748 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
500 KB |
Output is correct |
2 |
Runtime error |
990 ms |
728 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Runtime error |
58 ms |
748 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |