#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int N = 150000;
int dp[N], nx[N];
void solve() {
int m;
ll x;
cin >> m >> x;
ll mins = 0, maxs = 0;
vector<pii> v;
for (int i = -m; i <= m; ++i) {
int f;
cin >> f;
if (i < 0) mins += f * i;
else maxs += f * i;
int z = 1;
while (f > z) {
v.push_back({z * i, z});
f -= z;
z *= 2;
}
if (f > 0) v.push_back({f * i, f});
}
memset(dp, 0xc0, sizeof dp);
memset(nx, 0xc0, sizeof nx);
dp[0] = nx[0] = 0;
for (pii p : v) {
for (int i = -70000; i <= 70000; ++i) {
int j = i + p.first;
if (-70000 <= j && j <= 70000) nx[(j + N) % N] = max(nx[(j + N) % N], dp[(i + N) % N] + p.second);
}
copy(nx, nx+N, dp);
}
if (x < mins || x > maxs) cout << "impossible\n";
else cout << (dp[(x + N) % N] < 0 ? "impossible" : to_string(dp[(x + N) % N])) << '\n';
}
int main() {
cin.tie(0) -> sync_with_stdio(0);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1628 KB |
Output is correct |
2 |
Correct |
3 ms |
1624 KB |
Output is correct |
3 |
Correct |
2 ms |
1624 KB |
Output is correct |
4 |
Correct |
11 ms |
1628 KB |
Output is correct |
5 |
Correct |
166 ms |
1628 KB |
Output is correct |
6 |
Correct |
175 ms |
1628 KB |
Output is correct |
7 |
Correct |
72 ms |
1628 KB |
Output is correct |
8 |
Correct |
166 ms |
1628 KB |
Output is correct |
9 |
Correct |
205 ms |
1628 KB |
Output is correct |
10 |
Correct |
7 ms |
1624 KB |
Output is correct |
11 |
Correct |
6 ms |
1624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1628 KB |
Output is correct |
2 |
Correct |
3 ms |
1624 KB |
Output is correct |
3 |
Correct |
2 ms |
1624 KB |
Output is correct |
4 |
Correct |
11 ms |
1628 KB |
Output is correct |
5 |
Correct |
166 ms |
1628 KB |
Output is correct |
6 |
Correct |
175 ms |
1628 KB |
Output is correct |
7 |
Correct |
72 ms |
1628 KB |
Output is correct |
8 |
Correct |
166 ms |
1628 KB |
Output is correct |
9 |
Correct |
205 ms |
1628 KB |
Output is correct |
10 |
Correct |
7 ms |
1624 KB |
Output is correct |
11 |
Correct |
6 ms |
1624 KB |
Output is correct |
12 |
Correct |
4 ms |
1880 KB |
Output is correct |
13 |
Correct |
3 ms |
1628 KB |
Output is correct |
14 |
Correct |
2 ms |
1628 KB |
Output is correct |
15 |
Correct |
11 ms |
1624 KB |
Output is correct |
16 |
Correct |
165 ms |
1624 KB |
Output is correct |
17 |
Correct |
168 ms |
1628 KB |
Output is correct |
18 |
Correct |
70 ms |
1628 KB |
Output is correct |
19 |
Correct |
167 ms |
1624 KB |
Output is correct |
20 |
Correct |
208 ms |
1628 KB |
Output is correct |
21 |
Correct |
6 ms |
1624 KB |
Output is correct |
22 |
Correct |
7 ms |
1624 KB |
Output is correct |
23 |
Correct |
431 ms |
1628 KB |
Output is correct |
24 |
Incorrect |
394 ms |
1632 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
1628 KB |
Output is correct |
2 |
Incorrect |
27 ms |
1636 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
1628 KB |
Output is correct |
2 |
Incorrect |
27 ms |
1636 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
1628 KB |
Output is correct |
2 |
Incorrect |
27 ms |
1636 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1628 KB |
Output is correct |
2 |
Correct |
3 ms |
1624 KB |
Output is correct |
3 |
Correct |
2 ms |
1624 KB |
Output is correct |
4 |
Correct |
11 ms |
1628 KB |
Output is correct |
5 |
Correct |
166 ms |
1628 KB |
Output is correct |
6 |
Correct |
175 ms |
1628 KB |
Output is correct |
7 |
Correct |
72 ms |
1628 KB |
Output is correct |
8 |
Correct |
166 ms |
1628 KB |
Output is correct |
9 |
Correct |
205 ms |
1628 KB |
Output is correct |
10 |
Correct |
7 ms |
1624 KB |
Output is correct |
11 |
Correct |
6 ms |
1624 KB |
Output is correct |
12 |
Correct |
11 ms |
1628 KB |
Output is correct |
13 |
Incorrect |
27 ms |
1636 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
1628 KB |
Output is correct |
2 |
Incorrect |
27 ms |
1636 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1628 KB |
Output is correct |
2 |
Correct |
3 ms |
1624 KB |
Output is correct |
3 |
Correct |
2 ms |
1624 KB |
Output is correct |
4 |
Correct |
11 ms |
1628 KB |
Output is correct |
5 |
Correct |
166 ms |
1628 KB |
Output is correct |
6 |
Correct |
175 ms |
1628 KB |
Output is correct |
7 |
Correct |
72 ms |
1628 KB |
Output is correct |
8 |
Correct |
166 ms |
1628 KB |
Output is correct |
9 |
Correct |
205 ms |
1628 KB |
Output is correct |
10 |
Correct |
7 ms |
1624 KB |
Output is correct |
11 |
Correct |
6 ms |
1624 KB |
Output is correct |
12 |
Correct |
4 ms |
1880 KB |
Output is correct |
13 |
Correct |
3 ms |
1628 KB |
Output is correct |
14 |
Correct |
2 ms |
1628 KB |
Output is correct |
15 |
Correct |
11 ms |
1624 KB |
Output is correct |
16 |
Correct |
165 ms |
1624 KB |
Output is correct |
17 |
Correct |
168 ms |
1628 KB |
Output is correct |
18 |
Correct |
70 ms |
1628 KB |
Output is correct |
19 |
Correct |
167 ms |
1624 KB |
Output is correct |
20 |
Correct |
208 ms |
1628 KB |
Output is correct |
21 |
Correct |
6 ms |
1624 KB |
Output is correct |
22 |
Correct |
7 ms |
1624 KB |
Output is correct |
23 |
Correct |
431 ms |
1628 KB |
Output is correct |
24 |
Incorrect |
394 ms |
1632 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
1628 KB |
Output is correct |
2 |
Incorrect |
27 ms |
1636 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1628 KB |
Output is correct |
2 |
Correct |
3 ms |
1624 KB |
Output is correct |
3 |
Correct |
2 ms |
1624 KB |
Output is correct |
4 |
Correct |
11 ms |
1628 KB |
Output is correct |
5 |
Correct |
166 ms |
1628 KB |
Output is correct |
6 |
Correct |
175 ms |
1628 KB |
Output is correct |
7 |
Correct |
72 ms |
1628 KB |
Output is correct |
8 |
Correct |
166 ms |
1628 KB |
Output is correct |
9 |
Correct |
205 ms |
1628 KB |
Output is correct |
10 |
Correct |
7 ms |
1624 KB |
Output is correct |
11 |
Correct |
6 ms |
1624 KB |
Output is correct |
12 |
Correct |
4 ms |
1880 KB |
Output is correct |
13 |
Correct |
3 ms |
1628 KB |
Output is correct |
14 |
Correct |
2 ms |
1628 KB |
Output is correct |
15 |
Correct |
11 ms |
1624 KB |
Output is correct |
16 |
Correct |
165 ms |
1624 KB |
Output is correct |
17 |
Correct |
168 ms |
1628 KB |
Output is correct |
18 |
Correct |
70 ms |
1628 KB |
Output is correct |
19 |
Correct |
167 ms |
1624 KB |
Output is correct |
20 |
Correct |
208 ms |
1628 KB |
Output is correct |
21 |
Correct |
6 ms |
1624 KB |
Output is correct |
22 |
Correct |
7 ms |
1624 KB |
Output is correct |
23 |
Correct |
431 ms |
1628 KB |
Output is correct |
24 |
Incorrect |
394 ms |
1632 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |