#include <bits/stdc++.h>
using namespace std;
short dp[2][505000*2+1],arr[301];
int br = 505000,n,m;
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);
cin>>m>>n;
for(int i = 0;i<2*m+1;i++){
cin>>arr[i];
}
for(int i = 2*m+1;i>=0;i--){
for(int j = 0;j<=505000*2;j++){
if(i==2*m+1){
if(j==n+br){
dp[i&1][j] = 0;
}else{
dp[i&1][j] = -3e4;
}
continue;
}
int ans = -3e4;
for(int e = 0;e<=arr[i];e++){
if(j+e*(i-m)>505000*2)break;
if(j+e*(i-m)<0)continue;
ans = max(ans,dp[!(i&1)][j+e*(i-m)]+e);
}
dp[i&1][j] = ans;
}
}
long long vl = dp[0][505000];
if(vl<0)cout<<"impossible\n";
else cout<<vl<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
4184 KB |
Output is correct |
2 |
Correct |
20 ms |
4184 KB |
Output is correct |
3 |
Correct |
12 ms |
4184 KB |
Output is correct |
4 |
Correct |
92 ms |
4188 KB |
Output is correct |
5 |
Correct |
159 ms |
4184 KB |
Output is correct |
6 |
Correct |
2742 ms |
4184 KB |
Output is correct |
7 |
Correct |
1163 ms |
4384 KB |
Output is correct |
8 |
Correct |
2593 ms |
4380 KB |
Output is correct |
9 |
Correct |
4721 ms |
4380 KB |
Output is correct |
10 |
Correct |
266 ms |
4384 KB |
Output is correct |
11 |
Correct |
253 ms |
4384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
4184 KB |
Output is correct |
2 |
Correct |
20 ms |
4184 KB |
Output is correct |
3 |
Correct |
12 ms |
4184 KB |
Output is correct |
4 |
Correct |
92 ms |
4188 KB |
Output is correct |
5 |
Correct |
159 ms |
4184 KB |
Output is correct |
6 |
Correct |
2742 ms |
4184 KB |
Output is correct |
7 |
Correct |
1163 ms |
4384 KB |
Output is correct |
8 |
Correct |
2593 ms |
4380 KB |
Output is correct |
9 |
Correct |
4721 ms |
4380 KB |
Output is correct |
10 |
Correct |
266 ms |
4384 KB |
Output is correct |
11 |
Correct |
253 ms |
4384 KB |
Output is correct |
12 |
Correct |
19 ms |
4184 KB |
Output is correct |
13 |
Correct |
23 ms |
4184 KB |
Output is correct |
14 |
Correct |
16 ms |
4184 KB |
Output is correct |
15 |
Correct |
92 ms |
4384 KB |
Output is correct |
16 |
Correct |
158 ms |
4184 KB |
Output is correct |
17 |
Correct |
2754 ms |
4384 KB |
Output is correct |
18 |
Correct |
1158 ms |
4380 KB |
Output is correct |
19 |
Correct |
2610 ms |
4432 KB |
Output is correct |
20 |
Correct |
4867 ms |
4380 KB |
Output is correct |
21 |
Correct |
270 ms |
4184 KB |
Output is correct |
22 |
Correct |
243 ms |
4384 KB |
Output is correct |
23 |
Correct |
332 ms |
4184 KB |
Output is correct |
24 |
Execution timed out |
5028 ms |
4184 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
90 ms |
4184 KB |
Output is correct |
2 |
Incorrect |
101 ms |
4184 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
90 ms |
4184 KB |
Output is correct |
2 |
Incorrect |
101 ms |
4184 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
90 ms |
4184 KB |
Output is correct |
2 |
Incorrect |
101 ms |
4184 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
4184 KB |
Output is correct |
2 |
Correct |
20 ms |
4184 KB |
Output is correct |
3 |
Correct |
12 ms |
4184 KB |
Output is correct |
4 |
Correct |
92 ms |
4188 KB |
Output is correct |
5 |
Correct |
159 ms |
4184 KB |
Output is correct |
6 |
Correct |
2742 ms |
4184 KB |
Output is correct |
7 |
Correct |
1163 ms |
4384 KB |
Output is correct |
8 |
Correct |
2593 ms |
4380 KB |
Output is correct |
9 |
Correct |
4721 ms |
4380 KB |
Output is correct |
10 |
Correct |
266 ms |
4384 KB |
Output is correct |
11 |
Correct |
253 ms |
4384 KB |
Output is correct |
12 |
Correct |
90 ms |
4184 KB |
Output is correct |
13 |
Incorrect |
101 ms |
4184 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
90 ms |
4184 KB |
Output is correct |
2 |
Incorrect |
101 ms |
4184 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
4184 KB |
Output is correct |
2 |
Correct |
20 ms |
4184 KB |
Output is correct |
3 |
Correct |
12 ms |
4184 KB |
Output is correct |
4 |
Correct |
92 ms |
4188 KB |
Output is correct |
5 |
Correct |
159 ms |
4184 KB |
Output is correct |
6 |
Correct |
2742 ms |
4184 KB |
Output is correct |
7 |
Correct |
1163 ms |
4384 KB |
Output is correct |
8 |
Correct |
2593 ms |
4380 KB |
Output is correct |
9 |
Correct |
4721 ms |
4380 KB |
Output is correct |
10 |
Correct |
266 ms |
4384 KB |
Output is correct |
11 |
Correct |
253 ms |
4384 KB |
Output is correct |
12 |
Correct |
19 ms |
4184 KB |
Output is correct |
13 |
Correct |
23 ms |
4184 KB |
Output is correct |
14 |
Correct |
16 ms |
4184 KB |
Output is correct |
15 |
Correct |
92 ms |
4384 KB |
Output is correct |
16 |
Correct |
158 ms |
4184 KB |
Output is correct |
17 |
Correct |
2754 ms |
4384 KB |
Output is correct |
18 |
Correct |
1158 ms |
4380 KB |
Output is correct |
19 |
Correct |
2610 ms |
4432 KB |
Output is correct |
20 |
Correct |
4867 ms |
4380 KB |
Output is correct |
21 |
Correct |
270 ms |
4184 KB |
Output is correct |
22 |
Correct |
243 ms |
4384 KB |
Output is correct |
23 |
Correct |
332 ms |
4184 KB |
Output is correct |
24 |
Execution timed out |
5028 ms |
4184 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
90 ms |
4184 KB |
Output is correct |
2 |
Incorrect |
101 ms |
4184 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
4184 KB |
Output is correct |
2 |
Correct |
20 ms |
4184 KB |
Output is correct |
3 |
Correct |
12 ms |
4184 KB |
Output is correct |
4 |
Correct |
92 ms |
4188 KB |
Output is correct |
5 |
Correct |
159 ms |
4184 KB |
Output is correct |
6 |
Correct |
2742 ms |
4184 KB |
Output is correct |
7 |
Correct |
1163 ms |
4384 KB |
Output is correct |
8 |
Correct |
2593 ms |
4380 KB |
Output is correct |
9 |
Correct |
4721 ms |
4380 KB |
Output is correct |
10 |
Correct |
266 ms |
4384 KB |
Output is correct |
11 |
Correct |
253 ms |
4384 KB |
Output is correct |
12 |
Correct |
19 ms |
4184 KB |
Output is correct |
13 |
Correct |
23 ms |
4184 KB |
Output is correct |
14 |
Correct |
16 ms |
4184 KB |
Output is correct |
15 |
Correct |
92 ms |
4384 KB |
Output is correct |
16 |
Correct |
158 ms |
4184 KB |
Output is correct |
17 |
Correct |
2754 ms |
4384 KB |
Output is correct |
18 |
Correct |
1158 ms |
4380 KB |
Output is correct |
19 |
Correct |
2610 ms |
4432 KB |
Output is correct |
20 |
Correct |
4867 ms |
4380 KB |
Output is correct |
21 |
Correct |
270 ms |
4184 KB |
Output is correct |
22 |
Correct |
243 ms |
4384 KB |
Output is correct |
23 |
Correct |
332 ms |
4184 KB |
Output is correct |
24 |
Execution timed out |
5028 ms |
4184 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |