#include <bits/stdc++.h>
#define vi vector<int>
#define ve vector
#define ll long long
#define vf vector<float>
#define vll vector<pair<ll,ll>>
#define ii pair<int,int>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 1e7
#define eps 1e-7
#define eps1 1e-2
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 2e5+5
using namespace std;
const int MOD = 1e4+7;
const int nax = 505;
const int nax2 = 30005;
typedef complex<int> Point;
#define X real()
#define Y imag()
int s[nax], dp[nax2*4][nax],m,l;
int solve(int sm, int pos){
if(pos > 2*m){
if(sm == l) return 0;
else return -INF;
}
if(dp[sm+nax2][pos] != -1) return dp[sm+nax2][pos];
dp[sm+nax2][pos] = -INF;
for (int i = 0; i <= s[pos]; ++i)
{
int a = solve(sm+(pos-m)*i,pos+1);
if(a!=-INF) dp[sm+nax2][pos] = max(dp[sm+nax2][pos], solve(sm+(pos-m)*i,pos+1)+ i );
}
return dp[sm+nax2][pos];
}
int main(){
optimise;
cin >> m >> l;
for (int i = 0; i < 2*m+1; ++i)
{
cin >> s[i];
}
int res = 0;
memset(dp, -1,sizeof dp);
res = solve(0,0);
if(res == -INF) cout << "impossible" << endl;
else cout << res << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
100 ms |
237520 KB |
Output is correct |
2 |
Correct |
89 ms |
237444 KB |
Output is correct |
3 |
Correct |
86 ms |
237472 KB |
Output is correct |
4 |
Correct |
87 ms |
237484 KB |
Output is correct |
5 |
Correct |
88 ms |
237492 KB |
Output is correct |
6 |
Runtime error |
1256 ms |
481364 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
100 ms |
237520 KB |
Output is correct |
2 |
Correct |
89 ms |
237444 KB |
Output is correct |
3 |
Correct |
86 ms |
237472 KB |
Output is correct |
4 |
Correct |
87 ms |
237484 KB |
Output is correct |
5 |
Correct |
88 ms |
237492 KB |
Output is correct |
6 |
Runtime error |
1256 ms |
481364 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
93 ms |
237516 KB |
Output is correct |
2 |
Incorrect |
124 ms |
237480 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
93 ms |
237516 KB |
Output is correct |
2 |
Incorrect |
124 ms |
237480 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
93 ms |
237516 KB |
Output is correct |
2 |
Incorrect |
124 ms |
237480 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
100 ms |
237520 KB |
Output is correct |
2 |
Correct |
89 ms |
237444 KB |
Output is correct |
3 |
Correct |
86 ms |
237472 KB |
Output is correct |
4 |
Correct |
87 ms |
237484 KB |
Output is correct |
5 |
Correct |
88 ms |
237492 KB |
Output is correct |
6 |
Runtime error |
1256 ms |
481364 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
93 ms |
237516 KB |
Output is correct |
2 |
Incorrect |
124 ms |
237480 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
100 ms |
237520 KB |
Output is correct |
2 |
Correct |
89 ms |
237444 KB |
Output is correct |
3 |
Correct |
86 ms |
237472 KB |
Output is correct |
4 |
Correct |
87 ms |
237484 KB |
Output is correct |
5 |
Correct |
88 ms |
237492 KB |
Output is correct |
6 |
Runtime error |
1256 ms |
481364 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
93 ms |
237516 KB |
Output is correct |
2 |
Incorrect |
124 ms |
237480 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
100 ms |
237520 KB |
Output is correct |
2 |
Correct |
89 ms |
237444 KB |
Output is correct |
3 |
Correct |
86 ms |
237472 KB |
Output is correct |
4 |
Correct |
87 ms |
237484 KB |
Output is correct |
5 |
Correct |
88 ms |
237492 KB |
Output is correct |
6 |
Runtime error |
1256 ms |
481364 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |