#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int m;
ll L, all = 0;
cin >> m >> L;
vector<ll> _a(2 * m + 1), _b(2 * m + 1);
auto a = _a.data() + m, b = _b.data() + m;
for (int i = -m; i <= m; i++) {
cin >> a[i], all += max(0, i) * a[i];
}
if (all < L) cout << "impossible\n", exit(0);
ll ans = a[0];
for (int i = -1; i >= -m; i--) {
b[i] = min(a[i], (all - L) / -i);
ans += b[i], L -= b[i] * i, a[i] -= b[i];
}
for (int i = 1; i <= m; i++) {
b[i] = min(a[i], L / i);
ans += b[i], L -= b[i] * i, a[i] -= b[i];
}
int lim = m * L;
vector<int> f(2 * lim + 1, -1e9);
f[lim] = 0;
for (int i = -m; i <= m; i++) if (i) {
vector<int> g(2 * lim + 1, -1e9);
for (int j = -lim; j <= lim; j++) if (f[lim + j] > -1e8) {
for (int k = 0; k <= a[i]; k++) if (j + i * k >= -lim && j + i * k <= lim) {
g[lim + j + i * k] = max(g[lim + j + i * k], f[lim + j] + k);
}
for (int k = 0; k <= b[i]; k++) if (j - i * k >= -lim && j - i * k <= lim) {
g[lim + j - i * k] = max(g[lim + j - i * k], f[lim + j] - k);
}
}
swap(f, g);
}
if (f[L + lim] < -1e8) cout << "impossible\n";
else cout << ans + f[L + lim] << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Incorrect |
2049 ms |
292 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Incorrect |
2049 ms |
292 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
5060 ms |
212 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
5060 ms |
212 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
5060 ms |
212 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Incorrect |
2049 ms |
292 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
5060 ms |
212 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Incorrect |
2049 ms |
292 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
5060 ms |
212 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Incorrect |
2049 ms |
292 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |