#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 25*50*51;
const int INF = 1e8;
int main(){
cin.tie(0);
ios_base::sync_with_stdio(false);
int M; ll L;
cin >> M >> L;
vector<int> a(2*M+1);
for(int i = 0; i < 2*M+1; ++i) cin >> a[i];
if(L > MAX || L < -MAX){
cout << "impossible\n";
return 0;
}
vector<int> dp(2*MAX+1, -INF);
dp[MAX] = 0;
for(int i = 0; i < 2*M+1; ++i){
int v = i-M;
vector<int> dp2(2*MAX+1, -INF);
for(int j = 0; j < 2*MAX+1; ++j){
for(int k = 0; k <= a[i]; ++k){
if(j+v*k < 0 || j+v*k >= 2*MAX+1) break;
dp2[j+v*k] = max(dp2[j+v*k], dp[j]+k);
}
}
dp = dp2;
}
if(dp[MAX+L] < 0) cout << "impossible\n";
else cout << dp[MAX+L] << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1248 KB |
Output is correct |
2 |
Correct |
4 ms |
1248 KB |
Output is correct |
3 |
Correct |
2 ms |
1248 KB |
Output is correct |
4 |
Correct |
16 ms |
1248 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
439 ms |
1248 KB |
Output is correct |
7 |
Correct |
190 ms |
1248 KB |
Output is correct |
8 |
Correct |
437 ms |
1332 KB |
Output is correct |
9 |
Correct |
797 ms |
1364 KB |
Output is correct |
10 |
Correct |
40 ms |
1248 KB |
Output is correct |
11 |
Correct |
34 ms |
1248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1248 KB |
Output is correct |
2 |
Correct |
4 ms |
1248 KB |
Output is correct |
3 |
Correct |
2 ms |
1248 KB |
Output is correct |
4 |
Correct |
16 ms |
1248 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
439 ms |
1248 KB |
Output is correct |
7 |
Correct |
190 ms |
1248 KB |
Output is correct |
8 |
Correct |
437 ms |
1332 KB |
Output is correct |
9 |
Correct |
797 ms |
1364 KB |
Output is correct |
10 |
Correct |
40 ms |
1248 KB |
Output is correct |
11 |
Correct |
34 ms |
1248 KB |
Output is correct |
12 |
Correct |
4 ms |
1248 KB |
Output is correct |
13 |
Correct |
4 ms |
1248 KB |
Output is correct |
14 |
Correct |
3 ms |
1248 KB |
Output is correct |
15 |
Correct |
17 ms |
1248 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
433 ms |
1248 KB |
Output is correct |
18 |
Correct |
203 ms |
1248 KB |
Output is correct |
19 |
Correct |
409 ms |
1248 KB |
Output is correct |
20 |
Correct |
768 ms |
1248 KB |
Output is correct |
21 |
Correct |
41 ms |
1248 KB |
Output is correct |
22 |
Correct |
34 ms |
1248 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Incorrect |
1587 ms |
1248 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
1248 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 |
19 ms |
1248 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 |
19 ms |
1248 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 |
4 ms |
1248 KB |
Output is correct |
2 |
Correct |
4 ms |
1248 KB |
Output is correct |
3 |
Correct |
2 ms |
1248 KB |
Output is correct |
4 |
Correct |
16 ms |
1248 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
439 ms |
1248 KB |
Output is correct |
7 |
Correct |
190 ms |
1248 KB |
Output is correct |
8 |
Correct |
437 ms |
1332 KB |
Output is correct |
9 |
Correct |
797 ms |
1364 KB |
Output is correct |
10 |
Correct |
40 ms |
1248 KB |
Output is correct |
11 |
Correct |
34 ms |
1248 KB |
Output is correct |
12 |
Correct |
19 ms |
1248 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 |
19 ms |
1248 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 |
4 ms |
1248 KB |
Output is correct |
2 |
Correct |
4 ms |
1248 KB |
Output is correct |
3 |
Correct |
2 ms |
1248 KB |
Output is correct |
4 |
Correct |
16 ms |
1248 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
439 ms |
1248 KB |
Output is correct |
7 |
Correct |
190 ms |
1248 KB |
Output is correct |
8 |
Correct |
437 ms |
1332 KB |
Output is correct |
9 |
Correct |
797 ms |
1364 KB |
Output is correct |
10 |
Correct |
40 ms |
1248 KB |
Output is correct |
11 |
Correct |
34 ms |
1248 KB |
Output is correct |
12 |
Correct |
4 ms |
1248 KB |
Output is correct |
13 |
Correct |
4 ms |
1248 KB |
Output is correct |
14 |
Correct |
3 ms |
1248 KB |
Output is correct |
15 |
Correct |
17 ms |
1248 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
433 ms |
1248 KB |
Output is correct |
18 |
Correct |
203 ms |
1248 KB |
Output is correct |
19 |
Correct |
409 ms |
1248 KB |
Output is correct |
20 |
Correct |
768 ms |
1248 KB |
Output is correct |
21 |
Correct |
41 ms |
1248 KB |
Output is correct |
22 |
Correct |
34 ms |
1248 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Incorrect |
1587 ms |
1248 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
1248 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 |
4 ms |
1248 KB |
Output is correct |
2 |
Correct |
4 ms |
1248 KB |
Output is correct |
3 |
Correct |
2 ms |
1248 KB |
Output is correct |
4 |
Correct |
16 ms |
1248 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
439 ms |
1248 KB |
Output is correct |
7 |
Correct |
190 ms |
1248 KB |
Output is correct |
8 |
Correct |
437 ms |
1332 KB |
Output is correct |
9 |
Correct |
797 ms |
1364 KB |
Output is correct |
10 |
Correct |
40 ms |
1248 KB |
Output is correct |
11 |
Correct |
34 ms |
1248 KB |
Output is correct |
12 |
Correct |
4 ms |
1248 KB |
Output is correct |
13 |
Correct |
4 ms |
1248 KB |
Output is correct |
14 |
Correct |
3 ms |
1248 KB |
Output is correct |
15 |
Correct |
17 ms |
1248 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
433 ms |
1248 KB |
Output is correct |
18 |
Correct |
203 ms |
1248 KB |
Output is correct |
19 |
Correct |
409 ms |
1248 KB |
Output is correct |
20 |
Correct |
768 ms |
1248 KB |
Output is correct |
21 |
Correct |
41 ms |
1248 KB |
Output is correct |
22 |
Correct |
34 ms |
1248 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Incorrect |
1587 ms |
1248 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |