#include <bits/stdc++.h>
#define fr(i, a, b) for (int i = (a); i <= (b); ++i)
#define rf(i, a, b) for (int i = (a); i >= (b); --i)
#define fe(x, y) for (auto& x : y)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pw(x) (1LL << (x))
using namespace std;
mt19937_64 rng(228);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define fbo find_by_order
#define ook order_of_key
template <typename T>
bool umn(T& a, T b) {
return a > b ? a = b, 1 : 0;
}
template <typename T>
bool umx(T& a, T b) {
return a < b ? a = b, 1 : 0;
}
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T>
using ve = vector<T>;
const int N = 2e5 + 15e3;
const int M = 1e5;
int m;
ll l;
ve<int> a;
int dp_[N];
int& dp(int x) {
// if (x + M < 0 || x + M >= N) {
// cout << "GO " << x << "\n";
// exit(0);
// }
x += M;
assert(x >= 0 && x < N);
return dp_[x];
}
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#else
ios::sync_with_stdio(0);
cin.tie(0);
#endif
cin >> m >> l;
//
// ll sum = 0;
// fr (i, 1, m) {
// sum += 100 * i;
// }
fill(dp_, dp_ + N, -1e9);
// cout << dp(M) << "\n";
// cout << dp(-M) << "\n";
//
// return 0;
fr (i, -m, m) {
int x;
cin >> x;
fr (j, 1, x) a.pb(i);
}
// l += N / 2;
if (l + M < 0 || l + M >= N) {
cout << "impossible\n";
return 0;
}
dp(0) = 0;
//
// dp(M);
// dp(-M);
fe (cur, a) {
// cout << cur << " " << M << " " << -M + cur << "\n";
if (cur >= 0) {
rf (i, M, (-M + cur)) {
umx(dp(i), dp(i - cur) + 1);
}
} else {
fr (i, -M, M - cur) {
umx(dp(i), dp(i - cur) + 1);
}
}
}
// return 0;
if (dp(l) < 0) {
cout << "impossible\n";
return 0;
}
// fr (i, -10, 10) {
// cout << i << " " << dp(i) << "\n";
// }
cout << dp(l) << "\n";
// cout << sum << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1108 KB |
Output is correct |
2 |
Correct |
3 ms |
1108 KB |
Output is correct |
3 |
Correct |
3 ms |
1108 KB |
Output is correct |
4 |
Correct |
18 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
1108 KB |
Output is correct |
6 |
Correct |
719 ms |
1184 KB |
Output is correct |
7 |
Correct |
289 ms |
1108 KB |
Output is correct |
8 |
Correct |
688 ms |
1188 KB |
Output is correct |
9 |
Correct |
1293 ms |
1228 KB |
Output is correct |
10 |
Correct |
32 ms |
1108 KB |
Output is correct |
11 |
Correct |
23 ms |
1108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1108 KB |
Output is correct |
2 |
Correct |
3 ms |
1108 KB |
Output is correct |
3 |
Correct |
3 ms |
1108 KB |
Output is correct |
4 |
Correct |
18 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
1108 KB |
Output is correct |
6 |
Correct |
719 ms |
1184 KB |
Output is correct |
7 |
Correct |
289 ms |
1108 KB |
Output is correct |
8 |
Correct |
688 ms |
1188 KB |
Output is correct |
9 |
Correct |
1293 ms |
1228 KB |
Output is correct |
10 |
Correct |
32 ms |
1108 KB |
Output is correct |
11 |
Correct |
23 ms |
1108 KB |
Output is correct |
12 |
Correct |
4 ms |
1100 KB |
Output is correct |
13 |
Correct |
3 ms |
1108 KB |
Output is correct |
14 |
Correct |
2 ms |
1108 KB |
Output is correct |
15 |
Correct |
17 ms |
1108 KB |
Output is correct |
16 |
Correct |
1 ms |
1108 KB |
Output is correct |
17 |
Correct |
805 ms |
1184 KB |
Output is correct |
18 |
Correct |
282 ms |
1108 KB |
Output is correct |
19 |
Correct |
688 ms |
1176 KB |
Output is correct |
20 |
Correct |
1287 ms |
1212 KB |
Output is correct |
21 |
Correct |
32 ms |
1108 KB |
Output is correct |
22 |
Correct |
25 ms |
1164 KB |
Output is correct |
23 |
Correct |
1 ms |
1236 KB |
Output is correct |
24 |
Incorrect |
2598 ms |
1256 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
1160 KB |
Output is correct |
2 |
Runtime error |
513 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
1160 KB |
Output is correct |
2 |
Runtime error |
513 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
1160 KB |
Output is correct |
2 |
Runtime error |
513 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1108 KB |
Output is correct |
2 |
Correct |
3 ms |
1108 KB |
Output is correct |
3 |
Correct |
3 ms |
1108 KB |
Output is correct |
4 |
Correct |
18 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
1108 KB |
Output is correct |
6 |
Correct |
719 ms |
1184 KB |
Output is correct |
7 |
Correct |
289 ms |
1108 KB |
Output is correct |
8 |
Correct |
688 ms |
1188 KB |
Output is correct |
9 |
Correct |
1293 ms |
1228 KB |
Output is correct |
10 |
Correct |
32 ms |
1108 KB |
Output is correct |
11 |
Correct |
23 ms |
1108 KB |
Output is correct |
12 |
Correct |
18 ms |
1160 KB |
Output is correct |
13 |
Runtime error |
513 ms |
524288 KB |
Execution killed with signal 9 |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
1160 KB |
Output is correct |
2 |
Runtime error |
513 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1108 KB |
Output is correct |
2 |
Correct |
3 ms |
1108 KB |
Output is correct |
3 |
Correct |
3 ms |
1108 KB |
Output is correct |
4 |
Correct |
18 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
1108 KB |
Output is correct |
6 |
Correct |
719 ms |
1184 KB |
Output is correct |
7 |
Correct |
289 ms |
1108 KB |
Output is correct |
8 |
Correct |
688 ms |
1188 KB |
Output is correct |
9 |
Correct |
1293 ms |
1228 KB |
Output is correct |
10 |
Correct |
32 ms |
1108 KB |
Output is correct |
11 |
Correct |
23 ms |
1108 KB |
Output is correct |
12 |
Correct |
4 ms |
1100 KB |
Output is correct |
13 |
Correct |
3 ms |
1108 KB |
Output is correct |
14 |
Correct |
2 ms |
1108 KB |
Output is correct |
15 |
Correct |
17 ms |
1108 KB |
Output is correct |
16 |
Correct |
1 ms |
1108 KB |
Output is correct |
17 |
Correct |
805 ms |
1184 KB |
Output is correct |
18 |
Correct |
282 ms |
1108 KB |
Output is correct |
19 |
Correct |
688 ms |
1176 KB |
Output is correct |
20 |
Correct |
1287 ms |
1212 KB |
Output is correct |
21 |
Correct |
32 ms |
1108 KB |
Output is correct |
22 |
Correct |
25 ms |
1164 KB |
Output is correct |
23 |
Correct |
1 ms |
1236 KB |
Output is correct |
24 |
Incorrect |
2598 ms |
1256 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
1160 KB |
Output is correct |
2 |
Runtime error |
513 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1108 KB |
Output is correct |
2 |
Correct |
3 ms |
1108 KB |
Output is correct |
3 |
Correct |
3 ms |
1108 KB |
Output is correct |
4 |
Correct |
18 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
1108 KB |
Output is correct |
6 |
Correct |
719 ms |
1184 KB |
Output is correct |
7 |
Correct |
289 ms |
1108 KB |
Output is correct |
8 |
Correct |
688 ms |
1188 KB |
Output is correct |
9 |
Correct |
1293 ms |
1228 KB |
Output is correct |
10 |
Correct |
32 ms |
1108 KB |
Output is correct |
11 |
Correct |
23 ms |
1108 KB |
Output is correct |
12 |
Correct |
4 ms |
1100 KB |
Output is correct |
13 |
Correct |
3 ms |
1108 KB |
Output is correct |
14 |
Correct |
2 ms |
1108 KB |
Output is correct |
15 |
Correct |
17 ms |
1108 KB |
Output is correct |
16 |
Correct |
1 ms |
1108 KB |
Output is correct |
17 |
Correct |
805 ms |
1184 KB |
Output is correct |
18 |
Correct |
282 ms |
1108 KB |
Output is correct |
19 |
Correct |
688 ms |
1176 KB |
Output is correct |
20 |
Correct |
1287 ms |
1212 KB |
Output is correct |
21 |
Correct |
32 ms |
1108 KB |
Output is correct |
22 |
Correct |
25 ms |
1164 KB |
Output is correct |
23 |
Correct |
1 ms |
1236 KB |
Output is correct |
24 |
Incorrect |
2598 ms |
1256 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |