#include <bits/stdc++.h>
using namespace std;
#define int long long
int dp[3000010];
int a[10000],w[10000];
int siz;
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n,q;cin>>n>>q;
for (int i=-n;i<=n;i++){
int k;cin>>k;
int num=1;
while (k>=num){
k-=num;
a[++siz]=num*i;
w[siz]=num;
num<<=1;
}
if (k>0){
a[++siz]=k*i;
w[siz]=k;
}
}
//for (int i=1;i<=siz;i++) cout<<a[i]<<' '<<w[i]<<"\n";
for (int i=0;i<=1010000;i++) dp[i]=-1e18;
dp[505000]=0;
for (int i=1;i<=siz;i++){
if (a[i]<0){
for (int j=0;j<=1010000;j++){
if (j-a[i]>=0 && j-a[i]<=1010000 && dp[j-a[i]]!=-1e18){
dp[j]=max(dp[j],dp[j-a[i]]+w[i]);
}
}
continue;
}
for (int j=1010000;j>=0;j--){
if (j-a[i]>=0 && j-a[i]<=1010000 && dp[j-a[i]]!=-1e18){
dp[j]=max(dp[j],dp[j-a[i]]+w[i]);
}
}
}
if (q>505000 || q<-505000 || dp[505000+q]==-1e18) cout<<"impossible\n";
else cout<<dp[505000+q]<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
8284 KB |
Output is correct |
2 |
Correct |
10 ms |
8384 KB |
Output is correct |
3 |
Correct |
6 ms |
8376 KB |
Output is correct |
4 |
Correct |
35 ms |
8284 KB |
Output is correct |
5 |
Correct |
496 ms |
8364 KB |
Output is correct |
6 |
Correct |
517 ms |
8284 KB |
Output is correct |
7 |
Correct |
222 ms |
8368 KB |
Output is correct |
8 |
Correct |
496 ms |
8284 KB |
Output is correct |
9 |
Correct |
616 ms |
8284 KB |
Output is correct |
10 |
Correct |
21 ms |
8284 KB |
Output is correct |
11 |
Correct |
21 ms |
8284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
8284 KB |
Output is correct |
2 |
Correct |
10 ms |
8384 KB |
Output is correct |
3 |
Correct |
6 ms |
8376 KB |
Output is correct |
4 |
Correct |
35 ms |
8284 KB |
Output is correct |
5 |
Correct |
496 ms |
8364 KB |
Output is correct |
6 |
Correct |
517 ms |
8284 KB |
Output is correct |
7 |
Correct |
222 ms |
8368 KB |
Output is correct |
8 |
Correct |
496 ms |
8284 KB |
Output is correct |
9 |
Correct |
616 ms |
8284 KB |
Output is correct |
10 |
Correct |
21 ms |
8284 KB |
Output is correct |
11 |
Correct |
21 ms |
8284 KB |
Output is correct |
12 |
Correct |
12 ms |
8284 KB |
Output is correct |
13 |
Correct |
12 ms |
8172 KB |
Output is correct |
14 |
Correct |
8 ms |
8280 KB |
Output is correct |
15 |
Correct |
37 ms |
8320 KB |
Output is correct |
16 |
Correct |
501 ms |
8284 KB |
Output is correct |
17 |
Correct |
502 ms |
8144 KB |
Output is correct |
18 |
Correct |
209 ms |
8284 KB |
Output is correct |
19 |
Correct |
502 ms |
8284 KB |
Output is correct |
20 |
Correct |
662 ms |
8372 KB |
Output is correct |
21 |
Correct |
22 ms |
8280 KB |
Output is correct |
22 |
Correct |
21 ms |
8284 KB |
Output is correct |
23 |
Correct |
1224 ms |
8284 KB |
Output is correct |
24 |
Correct |
1225 ms |
8380 KB |
Output is correct |
25 |
Correct |
447 ms |
8368 KB |
Output is correct |
26 |
Correct |
1569 ms |
8284 KB |
Output is correct |
27 |
Correct |
1527 ms |
8284 KB |
Output is correct |
28 |
Correct |
34 ms |
8284 KB |
Output is correct |
29 |
Correct |
31 ms |
8144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
8284 KB |
Output is correct |
2 |
Incorrect |
504 ms |
8368 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
8284 KB |
Output is correct |
2 |
Incorrect |
504 ms |
8368 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
8284 KB |
Output is correct |
2 |
Incorrect |
504 ms |
8368 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
8284 KB |
Output is correct |
2 |
Correct |
10 ms |
8384 KB |
Output is correct |
3 |
Correct |
6 ms |
8376 KB |
Output is correct |
4 |
Correct |
35 ms |
8284 KB |
Output is correct |
5 |
Correct |
496 ms |
8364 KB |
Output is correct |
6 |
Correct |
517 ms |
8284 KB |
Output is correct |
7 |
Correct |
222 ms |
8368 KB |
Output is correct |
8 |
Correct |
496 ms |
8284 KB |
Output is correct |
9 |
Correct |
616 ms |
8284 KB |
Output is correct |
10 |
Correct |
21 ms |
8284 KB |
Output is correct |
11 |
Correct |
21 ms |
8284 KB |
Output is correct |
12 |
Correct |
35 ms |
8284 KB |
Output is correct |
13 |
Incorrect |
504 ms |
8368 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
8284 KB |
Output is correct |
2 |
Incorrect |
504 ms |
8368 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
8284 KB |
Output is correct |
2 |
Correct |
10 ms |
8384 KB |
Output is correct |
3 |
Correct |
6 ms |
8376 KB |
Output is correct |
4 |
Correct |
35 ms |
8284 KB |
Output is correct |
5 |
Correct |
496 ms |
8364 KB |
Output is correct |
6 |
Correct |
517 ms |
8284 KB |
Output is correct |
7 |
Correct |
222 ms |
8368 KB |
Output is correct |
8 |
Correct |
496 ms |
8284 KB |
Output is correct |
9 |
Correct |
616 ms |
8284 KB |
Output is correct |
10 |
Correct |
21 ms |
8284 KB |
Output is correct |
11 |
Correct |
21 ms |
8284 KB |
Output is correct |
12 |
Correct |
12 ms |
8284 KB |
Output is correct |
13 |
Correct |
12 ms |
8172 KB |
Output is correct |
14 |
Correct |
8 ms |
8280 KB |
Output is correct |
15 |
Correct |
37 ms |
8320 KB |
Output is correct |
16 |
Correct |
501 ms |
8284 KB |
Output is correct |
17 |
Correct |
502 ms |
8144 KB |
Output is correct |
18 |
Correct |
209 ms |
8284 KB |
Output is correct |
19 |
Correct |
502 ms |
8284 KB |
Output is correct |
20 |
Correct |
662 ms |
8372 KB |
Output is correct |
21 |
Correct |
22 ms |
8280 KB |
Output is correct |
22 |
Correct |
21 ms |
8284 KB |
Output is correct |
23 |
Correct |
1224 ms |
8284 KB |
Output is correct |
24 |
Correct |
1225 ms |
8380 KB |
Output is correct |
25 |
Correct |
447 ms |
8368 KB |
Output is correct |
26 |
Correct |
1569 ms |
8284 KB |
Output is correct |
27 |
Correct |
1527 ms |
8284 KB |
Output is correct |
28 |
Correct |
34 ms |
8284 KB |
Output is correct |
29 |
Correct |
31 ms |
8144 KB |
Output is correct |
30 |
Correct |
35 ms |
8284 KB |
Output is correct |
31 |
Incorrect |
504 ms |
8368 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
8284 KB |
Output is correct |
2 |
Incorrect |
504 ms |
8368 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
8284 KB |
Output is correct |
2 |
Correct |
10 ms |
8384 KB |
Output is correct |
3 |
Correct |
6 ms |
8376 KB |
Output is correct |
4 |
Correct |
35 ms |
8284 KB |
Output is correct |
5 |
Correct |
496 ms |
8364 KB |
Output is correct |
6 |
Correct |
517 ms |
8284 KB |
Output is correct |
7 |
Correct |
222 ms |
8368 KB |
Output is correct |
8 |
Correct |
496 ms |
8284 KB |
Output is correct |
9 |
Correct |
616 ms |
8284 KB |
Output is correct |
10 |
Correct |
21 ms |
8284 KB |
Output is correct |
11 |
Correct |
21 ms |
8284 KB |
Output is correct |
12 |
Correct |
12 ms |
8284 KB |
Output is correct |
13 |
Correct |
12 ms |
8172 KB |
Output is correct |
14 |
Correct |
8 ms |
8280 KB |
Output is correct |
15 |
Correct |
37 ms |
8320 KB |
Output is correct |
16 |
Correct |
501 ms |
8284 KB |
Output is correct |
17 |
Correct |
502 ms |
8144 KB |
Output is correct |
18 |
Correct |
209 ms |
8284 KB |
Output is correct |
19 |
Correct |
502 ms |
8284 KB |
Output is correct |
20 |
Correct |
662 ms |
8372 KB |
Output is correct |
21 |
Correct |
22 ms |
8280 KB |
Output is correct |
22 |
Correct |
21 ms |
8284 KB |
Output is correct |
23 |
Correct |
1224 ms |
8284 KB |
Output is correct |
24 |
Correct |
1225 ms |
8380 KB |
Output is correct |
25 |
Correct |
447 ms |
8368 KB |
Output is correct |
26 |
Correct |
1569 ms |
8284 KB |
Output is correct |
27 |
Correct |
1527 ms |
8284 KB |
Output is correct |
28 |
Correct |
34 ms |
8284 KB |
Output is correct |
29 |
Correct |
31 ms |
8144 KB |
Output is correct |
30 |
Correct |
35 ms |
8284 KB |
Output is correct |
31 |
Incorrect |
504 ms |
8368 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |