#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
int 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 = 1;i<=2*m+1;i++){
cin>>arr[i];
}
for(int i = 0;i<=505000*2;i++){
dp[0][i] = -3e4;
if(i==505000)dp[0][i] = 0;
}
for(int i = 1;i<=2*m+1;i++){
for(int j = 0;j<=(505000*2);j++){
int ans = -3e4;
for(int e = 0;e<=arr[i];e++){
if(j-e*(i-1-m)>505000*2)continue;
if(j-e*(i-1-m)<0)continue;
ans = max(ans,dp[!(i&1)][j-e*((i-1)-m)]+e);
}
dp[i&1][j] = ans;
}
}
long long vl = dp[(2*m+1)&1][n+505000];
if(vl<0)cout<<"impossible\n";
else cout<<vl<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
8280 KB |
Output is correct |
2 |
Correct |
19 ms |
8284 KB |
Output is correct |
3 |
Correct |
12 ms |
8284 KB |
Output is correct |
4 |
Correct |
85 ms |
8284 KB |
Output is correct |
5 |
Runtime error |
165 ms |
16464 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
8280 KB |
Output is correct |
2 |
Correct |
19 ms |
8284 KB |
Output is correct |
3 |
Correct |
12 ms |
8284 KB |
Output is correct |
4 |
Correct |
85 ms |
8284 KB |
Output is correct |
5 |
Runtime error |
165 ms |
16464 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
8280 KB |
Output is correct |
2 |
Runtime error |
106 ms |
16528 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
8280 KB |
Output is correct |
2 |
Runtime error |
106 ms |
16528 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
8280 KB |
Output is correct |
2 |
Runtime error |
106 ms |
16528 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
8280 KB |
Output is correct |
2 |
Correct |
19 ms |
8284 KB |
Output is correct |
3 |
Correct |
12 ms |
8284 KB |
Output is correct |
4 |
Correct |
85 ms |
8284 KB |
Output is correct |
5 |
Runtime error |
165 ms |
16464 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
8280 KB |
Output is correct |
2 |
Runtime error |
106 ms |
16528 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
8280 KB |
Output is correct |
2 |
Correct |
19 ms |
8284 KB |
Output is correct |
3 |
Correct |
12 ms |
8284 KB |
Output is correct |
4 |
Correct |
85 ms |
8284 KB |
Output is correct |
5 |
Runtime error |
165 ms |
16464 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
8280 KB |
Output is correct |
2 |
Runtime error |
106 ms |
16528 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
8280 KB |
Output is correct |
2 |
Correct |
19 ms |
8284 KB |
Output is correct |
3 |
Correct |
12 ms |
8284 KB |
Output is correct |
4 |
Correct |
85 ms |
8284 KB |
Output is correct |
5 |
Runtime error |
165 ms |
16464 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |