#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int MAXN = 100;
const int MXVAL = 505000;
int n;
ll target;
int cnt[2*MAXN+1];
int mx_use[MXVAL+1];
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> n >> target;
if (abs(target) > MXVAL) {
cout << "impossible\n";
return 0;
}
fill(mx_use, mx_use+MXVAL+1, -1);
mx_use[0] = 0;
for (int i = 0; i <= 2*n; i++) cin >> cnt[i];
if (target < 0) {
target *= -1;
for (int i = 0; i < n; i++) swap(cnt[i], cnt[2*n-i]);
}
for (int j = 1; j <= n; j++) {
for (int i = MXVAL; i >= j; i--) {
for (int p = 1; (p <= cnt[n+j]) && (i-p*j >= 0); p++)
if (mx_use[i-p*j] >= 0) mx_use[i] = max(mx_use[i], mx_use[i-p*j]+p);
}
}
for (int j = 1; j <= n; j++) {
for (int i = target; i <= MXVAL-j; i++) {
for (int p = 1; (p <= cnt[n-j]) && (i+p*j <= MXVAL); p++)
if (mx_use[i+p*j] >= 0) mx_use[i] = max(mx_use[i], mx_use[i+p*j]+p);
}
}
if (mx_use[target] == -1) {
cout << "impossible\n";
return 0;
}
cout << (mx_use[target]+cnt[n]) << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
2260 KB |
Output is correct |
2 |
Correct |
7 ms |
2260 KB |
Output is correct |
3 |
Correct |
5 ms |
2260 KB |
Output is correct |
4 |
Correct |
40 ms |
2260 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1589 ms |
2284 KB |
Output is correct |
7 |
Correct |
619 ms |
2284 KB |
Output is correct |
8 |
Correct |
1477 ms |
2284 KB |
Output is correct |
9 |
Correct |
2601 ms |
2276 KB |
Output is correct |
10 |
Correct |
106 ms |
2292 KB |
Output is correct |
11 |
Correct |
94 ms |
2280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
2260 KB |
Output is correct |
2 |
Correct |
7 ms |
2260 KB |
Output is correct |
3 |
Correct |
5 ms |
2260 KB |
Output is correct |
4 |
Correct |
40 ms |
2260 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1589 ms |
2284 KB |
Output is correct |
7 |
Correct |
619 ms |
2284 KB |
Output is correct |
8 |
Correct |
1477 ms |
2284 KB |
Output is correct |
9 |
Correct |
2601 ms |
2276 KB |
Output is correct |
10 |
Correct |
106 ms |
2292 KB |
Output is correct |
11 |
Correct |
94 ms |
2280 KB |
Output is correct |
12 |
Correct |
8 ms |
2260 KB |
Output is correct |
13 |
Correct |
7 ms |
2256 KB |
Output is correct |
14 |
Correct |
6 ms |
2260 KB |
Output is correct |
15 |
Correct |
43 ms |
2260 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1606 ms |
2380 KB |
Output is correct |
18 |
Correct |
622 ms |
2284 KB |
Output is correct |
19 |
Correct |
1492 ms |
2380 KB |
Output is correct |
20 |
Correct |
2602 ms |
2276 KB |
Output is correct |
21 |
Correct |
106 ms |
2280 KB |
Output is correct |
22 |
Correct |
95 ms |
2280 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Execution timed out |
5079 ms |
2260 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
2380 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
2380 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
2380 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
2260 KB |
Output is correct |
2 |
Correct |
7 ms |
2260 KB |
Output is correct |
3 |
Correct |
5 ms |
2260 KB |
Output is correct |
4 |
Correct |
40 ms |
2260 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1589 ms |
2284 KB |
Output is correct |
7 |
Correct |
619 ms |
2284 KB |
Output is correct |
8 |
Correct |
1477 ms |
2284 KB |
Output is correct |
9 |
Correct |
2601 ms |
2276 KB |
Output is correct |
10 |
Correct |
106 ms |
2292 KB |
Output is correct |
11 |
Correct |
94 ms |
2280 KB |
Output is correct |
12 |
Correct |
41 ms |
2380 KB |
Output is correct |
13 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
2380 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
2260 KB |
Output is correct |
2 |
Correct |
7 ms |
2260 KB |
Output is correct |
3 |
Correct |
5 ms |
2260 KB |
Output is correct |
4 |
Correct |
40 ms |
2260 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1589 ms |
2284 KB |
Output is correct |
7 |
Correct |
619 ms |
2284 KB |
Output is correct |
8 |
Correct |
1477 ms |
2284 KB |
Output is correct |
9 |
Correct |
2601 ms |
2276 KB |
Output is correct |
10 |
Correct |
106 ms |
2292 KB |
Output is correct |
11 |
Correct |
94 ms |
2280 KB |
Output is correct |
12 |
Correct |
8 ms |
2260 KB |
Output is correct |
13 |
Correct |
7 ms |
2256 KB |
Output is correct |
14 |
Correct |
6 ms |
2260 KB |
Output is correct |
15 |
Correct |
43 ms |
2260 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1606 ms |
2380 KB |
Output is correct |
18 |
Correct |
622 ms |
2284 KB |
Output is correct |
19 |
Correct |
1492 ms |
2380 KB |
Output is correct |
20 |
Correct |
2602 ms |
2276 KB |
Output is correct |
21 |
Correct |
106 ms |
2280 KB |
Output is correct |
22 |
Correct |
95 ms |
2280 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Execution timed out |
5079 ms |
2260 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
2380 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
2260 KB |
Output is correct |
2 |
Correct |
7 ms |
2260 KB |
Output is correct |
3 |
Correct |
5 ms |
2260 KB |
Output is correct |
4 |
Correct |
40 ms |
2260 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1589 ms |
2284 KB |
Output is correct |
7 |
Correct |
619 ms |
2284 KB |
Output is correct |
8 |
Correct |
1477 ms |
2284 KB |
Output is correct |
9 |
Correct |
2601 ms |
2276 KB |
Output is correct |
10 |
Correct |
106 ms |
2292 KB |
Output is correct |
11 |
Correct |
94 ms |
2280 KB |
Output is correct |
12 |
Correct |
8 ms |
2260 KB |
Output is correct |
13 |
Correct |
7 ms |
2256 KB |
Output is correct |
14 |
Correct |
6 ms |
2260 KB |
Output is correct |
15 |
Correct |
43 ms |
2260 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1606 ms |
2380 KB |
Output is correct |
18 |
Correct |
622 ms |
2284 KB |
Output is correct |
19 |
Correct |
1492 ms |
2380 KB |
Output is correct |
20 |
Correct |
2602 ms |
2276 KB |
Output is correct |
21 |
Correct |
106 ms |
2280 KB |
Output is correct |
22 |
Correct |
95 ms |
2280 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Execution timed out |
5079 ms |
2260 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |