#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;
}
}
if(n>=505000){
cout<<"impossible\n";
return 0;
}
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 |
18 ms |
8280 KB |
Output is correct |
3 |
Correct |
12 ms |
8284 KB |
Output is correct |
4 |
Correct |
86 ms |
8536 KB |
Output is correct |
5 |
Runtime error |
167 ms |
16540 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 |
18 ms |
8280 KB |
Output is correct |
3 |
Correct |
12 ms |
8284 KB |
Output is correct |
4 |
Correct |
86 ms |
8536 KB |
Output is correct |
5 |
Runtime error |
167 ms |
16540 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
84 ms |
8336 KB |
Output is correct |
2 |
Incorrect |
100 ms |
8280 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
84 ms |
8336 KB |
Output is correct |
2 |
Incorrect |
100 ms |
8280 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
84 ms |
8336 KB |
Output is correct |
2 |
Incorrect |
100 ms |
8280 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
8280 KB |
Output is correct |
2 |
Correct |
18 ms |
8280 KB |
Output is correct |
3 |
Correct |
12 ms |
8284 KB |
Output is correct |
4 |
Correct |
86 ms |
8536 KB |
Output is correct |
5 |
Runtime error |
167 ms |
16540 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
84 ms |
8336 KB |
Output is correct |
2 |
Incorrect |
100 ms |
8280 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
8280 KB |
Output is correct |
2 |
Correct |
18 ms |
8280 KB |
Output is correct |
3 |
Correct |
12 ms |
8284 KB |
Output is correct |
4 |
Correct |
86 ms |
8536 KB |
Output is correct |
5 |
Runtime error |
167 ms |
16540 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
84 ms |
8336 KB |
Output is correct |
2 |
Incorrect |
100 ms |
8280 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
8280 KB |
Output is correct |
2 |
Correct |
18 ms |
8280 KB |
Output is correct |
3 |
Correct |
12 ms |
8284 KB |
Output is correct |
4 |
Correct |
86 ms |
8536 KB |
Output is correct |
5 |
Runtime error |
167 ms |
16540 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |