#include <bits/stdc++.h>
using namespace std;
class negarr {
private:
int data[505000 * 2 + 1];
public:
negarr() { memset(data, 0, sizeof(data)); }
void reset() { fill(data, data + 505000 * 2 + 1, -1000000000); }
int &operator[](int i) { return data[i + 505000]; }
};
negarr a, knapsack;
int main() {
int m;
long long l;
cin >> m >> l;
if (l > 505000 || l < -505000) {
printf("impossible\n");
return 0;
}
knapsack.reset();
knapsack[0] = 0;
for (int i = -m; i <= m; i++) {
cin >> a[i];
negarr tmp;
tmp.reset();
if (i >= 0) {
for (int id = 505000 - i; id >= -505000; id--) {
for (int j = 1; j <= a[i]; j++)
tmp[id + j * i] = max(tmp[id + j * i], knapsack[id] + j);
}
} else if (i < 0) {
for (int id = -505000 - i; id <= 505000; id++) {
for (int j = 1; j <= a[i]; j++)
tmp[id + j * i] = max(tmp[id + j * i], knapsack[id] + j);
}
}
for (int id = -505000; id <= 505000; id++) {
knapsack[id] = max(knapsack[id], tmp[id]);
}
}
if (knapsack[l] >= 0)
printf("%d\n", knapsack[l]);
else
printf("impossible\n");
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
12116 KB |
Output is correct |
2 |
Correct |
31 ms |
12116 KB |
Output is correct |
3 |
Correct |
18 ms |
12152 KB |
Output is correct |
4 |
Correct |
113 ms |
12132 KB |
Output is correct |
5 |
Correct |
6 ms |
12116 KB |
Output is correct |
6 |
Runtime error |
1739 ms |
24428 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
12116 KB |
Output is correct |
2 |
Correct |
31 ms |
12116 KB |
Output is correct |
3 |
Correct |
18 ms |
12152 KB |
Output is correct |
4 |
Correct |
113 ms |
12132 KB |
Output is correct |
5 |
Correct |
6 ms |
12116 KB |
Output is correct |
6 |
Runtime error |
1739 ms |
24428 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
116 ms |
12136 KB |
Output is correct |
2 |
Incorrect |
6 ms |
12116 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
116 ms |
12136 KB |
Output is correct |
2 |
Incorrect |
6 ms |
12116 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
116 ms |
12136 KB |
Output is correct |
2 |
Incorrect |
6 ms |
12116 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
12116 KB |
Output is correct |
2 |
Correct |
31 ms |
12116 KB |
Output is correct |
3 |
Correct |
18 ms |
12152 KB |
Output is correct |
4 |
Correct |
113 ms |
12132 KB |
Output is correct |
5 |
Correct |
6 ms |
12116 KB |
Output is correct |
6 |
Runtime error |
1739 ms |
24428 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
116 ms |
12136 KB |
Output is correct |
2 |
Incorrect |
6 ms |
12116 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
12116 KB |
Output is correct |
2 |
Correct |
31 ms |
12116 KB |
Output is correct |
3 |
Correct |
18 ms |
12152 KB |
Output is correct |
4 |
Correct |
113 ms |
12132 KB |
Output is correct |
5 |
Correct |
6 ms |
12116 KB |
Output is correct |
6 |
Runtime error |
1739 ms |
24428 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
116 ms |
12136 KB |
Output is correct |
2 |
Incorrect |
6 ms |
12116 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
12116 KB |
Output is correct |
2 |
Correct |
31 ms |
12116 KB |
Output is correct |
3 |
Correct |
18 ms |
12152 KB |
Output is correct |
4 |
Correct |
113 ms |
12132 KB |
Output is correct |
5 |
Correct |
6 ms |
12116 KB |
Output is correct |
6 |
Runtime error |
1739 ms |
24428 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |