#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF=1e18;
int M, L, A[210], D[1200010];
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>M>>L;
for(int i=0; i<=2*M; i++) cin>>A[i];
for(int j=0; j<=1200000; j++) D[j]=-INF;
D[600000]=0;
for(int i=-M; i<=M; i++) {
while(A[i+M]--) {
if(i>0) for(int j=1200000; j>=i; j--) D[j]=max(D[j], D[j-i]+1);
else for(int j=0; j<=1200000; j++) D[j]=max(D[j], D[j-i]+1);
}
}
if(abs(L)<=600000 && D[600000+L]>=0) cout<<D[600000+L]<<"\n";
else cout<<"impossible";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
9820 KB |
Output is correct |
2 |
Correct |
9 ms |
9820 KB |
Output is correct |
3 |
Correct |
9 ms |
9820 KB |
Output is correct |
4 |
Correct |
52 ms |
9752 KB |
Output is correct |
5 |
Correct |
1870 ms |
9832 KB |
Output is correct |
6 |
Correct |
1933 ms |
9820 KB |
Output is correct |
7 |
Correct |
767 ms |
9816 KB |
Output is correct |
8 |
Correct |
1804 ms |
9816 KB |
Output is correct |
9 |
Correct |
3407 ms |
9824 KB |
Output is correct |
10 |
Correct |
105 ms |
9816 KB |
Output is correct |
11 |
Correct |
69 ms |
9820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
9820 KB |
Output is correct |
2 |
Correct |
9 ms |
9820 KB |
Output is correct |
3 |
Correct |
9 ms |
9820 KB |
Output is correct |
4 |
Correct |
52 ms |
9752 KB |
Output is correct |
5 |
Correct |
1870 ms |
9832 KB |
Output is correct |
6 |
Correct |
1933 ms |
9820 KB |
Output is correct |
7 |
Correct |
767 ms |
9816 KB |
Output is correct |
8 |
Correct |
1804 ms |
9816 KB |
Output is correct |
9 |
Correct |
3407 ms |
9824 KB |
Output is correct |
10 |
Correct |
105 ms |
9816 KB |
Output is correct |
11 |
Correct |
69 ms |
9820 KB |
Output is correct |
12 |
Correct |
13 ms |
9820 KB |
Output is correct |
13 |
Correct |
10 ms |
9820 KB |
Output is correct |
14 |
Correct |
9 ms |
9820 KB |
Output is correct |
15 |
Correct |
51 ms |
9824 KB |
Output is correct |
16 |
Correct |
1872 ms |
9824 KB |
Output is correct |
17 |
Correct |
1887 ms |
9824 KB |
Output is correct |
18 |
Correct |
796 ms |
9828 KB |
Output is correct |
19 |
Correct |
1698 ms |
9816 KB |
Output is correct |
20 |
Correct |
3395 ms |
9828 KB |
Output is correct |
21 |
Correct |
99 ms |
9820 KB |
Output is correct |
22 |
Correct |
70 ms |
9828 KB |
Output is correct |
23 |
Execution timed out |
5004 ms |
9820 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
9816 KB |
Output is correct |
2 |
Execution timed out |
5077 ms |
9820 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
9816 KB |
Output is correct |
2 |
Execution timed out |
5077 ms |
9820 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
9816 KB |
Output is correct |
2 |
Execution timed out |
5077 ms |
9820 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
9820 KB |
Output is correct |
2 |
Correct |
9 ms |
9820 KB |
Output is correct |
3 |
Correct |
9 ms |
9820 KB |
Output is correct |
4 |
Correct |
52 ms |
9752 KB |
Output is correct |
5 |
Correct |
1870 ms |
9832 KB |
Output is correct |
6 |
Correct |
1933 ms |
9820 KB |
Output is correct |
7 |
Correct |
767 ms |
9816 KB |
Output is correct |
8 |
Correct |
1804 ms |
9816 KB |
Output is correct |
9 |
Correct |
3407 ms |
9824 KB |
Output is correct |
10 |
Correct |
105 ms |
9816 KB |
Output is correct |
11 |
Correct |
69 ms |
9820 KB |
Output is correct |
12 |
Correct |
57 ms |
9816 KB |
Output is correct |
13 |
Execution timed out |
5077 ms |
9820 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
9816 KB |
Output is correct |
2 |
Execution timed out |
5077 ms |
9820 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
9820 KB |
Output is correct |
2 |
Correct |
9 ms |
9820 KB |
Output is correct |
3 |
Correct |
9 ms |
9820 KB |
Output is correct |
4 |
Correct |
52 ms |
9752 KB |
Output is correct |
5 |
Correct |
1870 ms |
9832 KB |
Output is correct |
6 |
Correct |
1933 ms |
9820 KB |
Output is correct |
7 |
Correct |
767 ms |
9816 KB |
Output is correct |
8 |
Correct |
1804 ms |
9816 KB |
Output is correct |
9 |
Correct |
3407 ms |
9824 KB |
Output is correct |
10 |
Correct |
105 ms |
9816 KB |
Output is correct |
11 |
Correct |
69 ms |
9820 KB |
Output is correct |
12 |
Correct |
13 ms |
9820 KB |
Output is correct |
13 |
Correct |
10 ms |
9820 KB |
Output is correct |
14 |
Correct |
9 ms |
9820 KB |
Output is correct |
15 |
Correct |
51 ms |
9824 KB |
Output is correct |
16 |
Correct |
1872 ms |
9824 KB |
Output is correct |
17 |
Correct |
1887 ms |
9824 KB |
Output is correct |
18 |
Correct |
796 ms |
9828 KB |
Output is correct |
19 |
Correct |
1698 ms |
9816 KB |
Output is correct |
20 |
Correct |
3395 ms |
9828 KB |
Output is correct |
21 |
Correct |
99 ms |
9820 KB |
Output is correct |
22 |
Correct |
70 ms |
9828 KB |
Output is correct |
23 |
Execution timed out |
5004 ms |
9820 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
9816 KB |
Output is correct |
2 |
Execution timed out |
5077 ms |
9820 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
9820 KB |
Output is correct |
2 |
Correct |
9 ms |
9820 KB |
Output is correct |
3 |
Correct |
9 ms |
9820 KB |
Output is correct |
4 |
Correct |
52 ms |
9752 KB |
Output is correct |
5 |
Correct |
1870 ms |
9832 KB |
Output is correct |
6 |
Correct |
1933 ms |
9820 KB |
Output is correct |
7 |
Correct |
767 ms |
9816 KB |
Output is correct |
8 |
Correct |
1804 ms |
9816 KB |
Output is correct |
9 |
Correct |
3407 ms |
9824 KB |
Output is correct |
10 |
Correct |
105 ms |
9816 KB |
Output is correct |
11 |
Correct |
69 ms |
9820 KB |
Output is correct |
12 |
Correct |
13 ms |
9820 KB |
Output is correct |
13 |
Correct |
10 ms |
9820 KB |
Output is correct |
14 |
Correct |
9 ms |
9820 KB |
Output is correct |
15 |
Correct |
51 ms |
9824 KB |
Output is correct |
16 |
Correct |
1872 ms |
9824 KB |
Output is correct |
17 |
Correct |
1887 ms |
9824 KB |
Output is correct |
18 |
Correct |
796 ms |
9828 KB |
Output is correct |
19 |
Correct |
1698 ms |
9816 KB |
Output is correct |
20 |
Correct |
3395 ms |
9828 KB |
Output is correct |
21 |
Correct |
99 ms |
9820 KB |
Output is correct |
22 |
Correct |
70 ms |
9828 KB |
Output is correct |
23 |
Execution timed out |
5004 ms |
9820 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |