#include<bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
int res[510000];
int main () {
cin.tie(0)->sync_with_stdio(0);
for(int i = 0;i<510000;i++)res[i]=-1e9;
res[0]=0;
long long m, l;
cin >> m >> l;
int a[2*m+1];
for(int i = 0;i<=2*m;i++) {
cin >> a[i];
}
if(l<0) {
l=-l;
reverse(a,a+2*m+1);
}
if(l>=510000) {
cout << "impossible\n";
return 0;
}
for(int i = m+1;i<=2*m;i++) {
for(int cnt=1;cnt<=a[i];cnt++) {
for(int j = 510000-1;j>=(i-m);j--) {
res[j]=max(res[j], res[j-(i-m)]+1);
}
}
}
for(int i = 0;i<=m-1;i++) {
for(int cnt=1;cnt<=a[i];cnt++) {
for(int j = 0;j<510000;j++) {
if((j-(i-m))<510000)res[j]=max(res[j], res[j-(i-m)]+1);
}
}
}
res[l]+=a[m];
if(res[l]<0)cout<<"impossible\n";
else cout << (res[l]) << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2260 KB |
Output is correct |
2 |
Correct |
6 ms |
2260 KB |
Output is correct |
3 |
Correct |
3 ms |
2260 KB |
Output is correct |
4 |
Correct |
15 ms |
2260 KB |
Output is correct |
5 |
Correct |
1 ms |
2260 KB |
Output is correct |
6 |
Correct |
1624 ms |
2288 KB |
Output is correct |
7 |
Correct |
752 ms |
2292 KB |
Output is correct |
8 |
Correct |
1554 ms |
2308 KB |
Output is correct |
9 |
Correct |
2933 ms |
2304 KB |
Output is correct |
10 |
Correct |
26 ms |
2260 KB |
Output is correct |
11 |
Correct |
23 ms |
2308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2260 KB |
Output is correct |
2 |
Correct |
6 ms |
2260 KB |
Output is correct |
3 |
Correct |
3 ms |
2260 KB |
Output is correct |
4 |
Correct |
15 ms |
2260 KB |
Output is correct |
5 |
Correct |
1 ms |
2260 KB |
Output is correct |
6 |
Correct |
1624 ms |
2288 KB |
Output is correct |
7 |
Correct |
752 ms |
2292 KB |
Output is correct |
8 |
Correct |
1554 ms |
2308 KB |
Output is correct |
9 |
Correct |
2933 ms |
2304 KB |
Output is correct |
10 |
Correct |
26 ms |
2260 KB |
Output is correct |
11 |
Correct |
23 ms |
2308 KB |
Output is correct |
12 |
Correct |
8 ms |
2312 KB |
Output is correct |
13 |
Correct |
6 ms |
2260 KB |
Output is correct |
14 |
Correct |
3 ms |
2260 KB |
Output is correct |
15 |
Correct |
15 ms |
2260 KB |
Output is correct |
16 |
Correct |
1 ms |
2260 KB |
Output is correct |
17 |
Correct |
1613 ms |
2292 KB |
Output is correct |
18 |
Correct |
741 ms |
2296 KB |
Output is correct |
19 |
Correct |
1555 ms |
2380 KB |
Output is correct |
20 |
Correct |
2949 ms |
2292 KB |
Output is correct |
21 |
Correct |
26 ms |
2260 KB |
Output is correct |
22 |
Correct |
22 ms |
2308 KB |
Output is correct |
23 |
Correct |
1 ms |
2260 KB |
Output is correct |
24 |
Execution timed out |
5058 ms |
2260 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
2260 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2260 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
2260 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2260 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
2260 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2260 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2260 KB |
Output is correct |
2 |
Correct |
6 ms |
2260 KB |
Output is correct |
3 |
Correct |
3 ms |
2260 KB |
Output is correct |
4 |
Correct |
15 ms |
2260 KB |
Output is correct |
5 |
Correct |
1 ms |
2260 KB |
Output is correct |
6 |
Correct |
1624 ms |
2288 KB |
Output is correct |
7 |
Correct |
752 ms |
2292 KB |
Output is correct |
8 |
Correct |
1554 ms |
2308 KB |
Output is correct |
9 |
Correct |
2933 ms |
2304 KB |
Output is correct |
10 |
Correct |
26 ms |
2260 KB |
Output is correct |
11 |
Correct |
23 ms |
2308 KB |
Output is correct |
12 |
Correct |
15 ms |
2260 KB |
Output is correct |
13 |
Incorrect |
1 ms |
2260 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
2260 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2260 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2260 KB |
Output is correct |
2 |
Correct |
6 ms |
2260 KB |
Output is correct |
3 |
Correct |
3 ms |
2260 KB |
Output is correct |
4 |
Correct |
15 ms |
2260 KB |
Output is correct |
5 |
Correct |
1 ms |
2260 KB |
Output is correct |
6 |
Correct |
1624 ms |
2288 KB |
Output is correct |
7 |
Correct |
752 ms |
2292 KB |
Output is correct |
8 |
Correct |
1554 ms |
2308 KB |
Output is correct |
9 |
Correct |
2933 ms |
2304 KB |
Output is correct |
10 |
Correct |
26 ms |
2260 KB |
Output is correct |
11 |
Correct |
23 ms |
2308 KB |
Output is correct |
12 |
Correct |
8 ms |
2312 KB |
Output is correct |
13 |
Correct |
6 ms |
2260 KB |
Output is correct |
14 |
Correct |
3 ms |
2260 KB |
Output is correct |
15 |
Correct |
15 ms |
2260 KB |
Output is correct |
16 |
Correct |
1 ms |
2260 KB |
Output is correct |
17 |
Correct |
1613 ms |
2292 KB |
Output is correct |
18 |
Correct |
741 ms |
2296 KB |
Output is correct |
19 |
Correct |
1555 ms |
2380 KB |
Output is correct |
20 |
Correct |
2949 ms |
2292 KB |
Output is correct |
21 |
Correct |
26 ms |
2260 KB |
Output is correct |
22 |
Correct |
22 ms |
2308 KB |
Output is correct |
23 |
Correct |
1 ms |
2260 KB |
Output is correct |
24 |
Execution timed out |
5058 ms |
2260 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
2260 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2260 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2260 KB |
Output is correct |
2 |
Correct |
6 ms |
2260 KB |
Output is correct |
3 |
Correct |
3 ms |
2260 KB |
Output is correct |
4 |
Correct |
15 ms |
2260 KB |
Output is correct |
5 |
Correct |
1 ms |
2260 KB |
Output is correct |
6 |
Correct |
1624 ms |
2288 KB |
Output is correct |
7 |
Correct |
752 ms |
2292 KB |
Output is correct |
8 |
Correct |
1554 ms |
2308 KB |
Output is correct |
9 |
Correct |
2933 ms |
2304 KB |
Output is correct |
10 |
Correct |
26 ms |
2260 KB |
Output is correct |
11 |
Correct |
23 ms |
2308 KB |
Output is correct |
12 |
Correct |
8 ms |
2312 KB |
Output is correct |
13 |
Correct |
6 ms |
2260 KB |
Output is correct |
14 |
Correct |
3 ms |
2260 KB |
Output is correct |
15 |
Correct |
15 ms |
2260 KB |
Output is correct |
16 |
Correct |
1 ms |
2260 KB |
Output is correct |
17 |
Correct |
1613 ms |
2292 KB |
Output is correct |
18 |
Correct |
741 ms |
2296 KB |
Output is correct |
19 |
Correct |
1555 ms |
2380 KB |
Output is correct |
20 |
Correct |
2949 ms |
2292 KB |
Output is correct |
21 |
Correct |
26 ms |
2260 KB |
Output is correct |
22 |
Correct |
22 ms |
2308 KB |
Output is correct |
23 |
Correct |
1 ms |
2260 KB |
Output is correct |
24 |
Execution timed out |
5058 ms |
2260 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |