#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <cstring>
using namespace std;
const int maxn=55, maxval=63755;
typedef long long ll;
int a[maxn*2];
int dp[maxval][maxn];
void dodaj1(int br, int x){
for(int i=x; i<maxval; i++){
for(int j=1; j<=br; j++){
if(dp[i-x][j-1]!=-1){
dp[i][j]=dp[i-x][j-1]+1;
}
}
}
for(int i=0; i<maxval; i++){
int maksi=-1;
for(int j=0; j<=br; j++){
maksi=max(maksi, dp[i][j]);
dp[i][j]=-1;
}
dp[i][0]=maksi;
}
}
void dodaj2(int br, int x){
for(int i=maxval-x-1; i>=0; i--){
for(int j=1; j<=br; j++){
if(dp[i+x][j-1]!=-1){
dp[i][j]=dp[i+x][j-1]+1;
}
}
}
for(int i=0; i<maxval; i++){
int maksi=-1;
for(int j=0; j<=br; j++){
maksi=max(maksi, dp[i][j]);
dp[i][j]=-1;
}
dp[i][0]=maksi;
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
memset(dp, -1, sizeof(dp));
int n;
ll l;
cin >> n >> l;
assert(n<maxn);
for(int i=0; i<n*2+1; i++){
cin >> a[i];
assert(a[i]<maxn);
}
dp[0][0]=a[n];
if(l<0){
l=-l;
for(int i=0; i<n; i++){
dodaj1(a[i], n-i);
}
for(int i=n+1; i<n*2+1; i++){
dodaj2(a[i], i-n);
}
}
else{
for(int i=n+1; i<n*2+1; i++){
dodaj1(a[i], i-n);
}
for(int i=0; i<n; i++){
dodaj2(a[i], n-i);
}
}
if(l>=maxval || dp[l][0]<1){
cout << "impossible\n";
}
else{
cout << dp[l][0] << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
14044 KB |
Output is correct |
2 |
Correct |
14 ms |
14048 KB |
Output is correct |
3 |
Correct |
10 ms |
14036 KB |
Output is correct |
4 |
Correct |
36 ms |
14036 KB |
Output is correct |
5 |
Correct |
437 ms |
14024 KB |
Output is correct |
6 |
Correct |
455 ms |
14036 KB |
Output is correct |
7 |
Correct |
236 ms |
14036 KB |
Output is correct |
8 |
Correct |
422 ms |
14056 KB |
Output is correct |
9 |
Correct |
713 ms |
14036 KB |
Output is correct |
10 |
Correct |
43 ms |
14036 KB |
Output is correct |
11 |
Correct |
70 ms |
14024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
14044 KB |
Output is correct |
2 |
Correct |
14 ms |
14048 KB |
Output is correct |
3 |
Correct |
10 ms |
14036 KB |
Output is correct |
4 |
Correct |
36 ms |
14036 KB |
Output is correct |
5 |
Correct |
437 ms |
14024 KB |
Output is correct |
6 |
Correct |
455 ms |
14036 KB |
Output is correct |
7 |
Correct |
236 ms |
14036 KB |
Output is correct |
8 |
Correct |
422 ms |
14056 KB |
Output is correct |
9 |
Correct |
713 ms |
14036 KB |
Output is correct |
10 |
Correct |
43 ms |
14036 KB |
Output is correct |
11 |
Correct |
70 ms |
14024 KB |
Output is correct |
12 |
Correct |
11 ms |
14004 KB |
Output is correct |
13 |
Correct |
16 ms |
14036 KB |
Output is correct |
14 |
Correct |
13 ms |
14036 KB |
Output is correct |
15 |
Correct |
31 ms |
14036 KB |
Output is correct |
16 |
Correct |
423 ms |
14036 KB |
Output is correct |
17 |
Correct |
521 ms |
14036 KB |
Output is correct |
18 |
Correct |
209 ms |
14020 KB |
Output is correct |
19 |
Correct |
436 ms |
14036 KB |
Output is correct |
20 |
Correct |
696 ms |
14036 KB |
Output is correct |
21 |
Correct |
48 ms |
14036 KB |
Output is correct |
22 |
Correct |
51 ms |
14036 KB |
Output is correct |
23 |
Runtime error |
18 ms |
28244 KB |
Execution killed with signal 6 |
24 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
14024 KB |
Output is correct |
2 |
Runtime error |
17 ms |
28244 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
14024 KB |
Output is correct |
2 |
Runtime error |
17 ms |
28244 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
14024 KB |
Output is correct |
2 |
Runtime error |
17 ms |
28244 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
14044 KB |
Output is correct |
2 |
Correct |
14 ms |
14048 KB |
Output is correct |
3 |
Correct |
10 ms |
14036 KB |
Output is correct |
4 |
Correct |
36 ms |
14036 KB |
Output is correct |
5 |
Correct |
437 ms |
14024 KB |
Output is correct |
6 |
Correct |
455 ms |
14036 KB |
Output is correct |
7 |
Correct |
236 ms |
14036 KB |
Output is correct |
8 |
Correct |
422 ms |
14056 KB |
Output is correct |
9 |
Correct |
713 ms |
14036 KB |
Output is correct |
10 |
Correct |
43 ms |
14036 KB |
Output is correct |
11 |
Correct |
70 ms |
14024 KB |
Output is correct |
12 |
Correct |
28 ms |
14024 KB |
Output is correct |
13 |
Runtime error |
17 ms |
28244 KB |
Execution killed with signal 6 |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
14024 KB |
Output is correct |
2 |
Runtime error |
17 ms |
28244 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
14044 KB |
Output is correct |
2 |
Correct |
14 ms |
14048 KB |
Output is correct |
3 |
Correct |
10 ms |
14036 KB |
Output is correct |
4 |
Correct |
36 ms |
14036 KB |
Output is correct |
5 |
Correct |
437 ms |
14024 KB |
Output is correct |
6 |
Correct |
455 ms |
14036 KB |
Output is correct |
7 |
Correct |
236 ms |
14036 KB |
Output is correct |
8 |
Correct |
422 ms |
14056 KB |
Output is correct |
9 |
Correct |
713 ms |
14036 KB |
Output is correct |
10 |
Correct |
43 ms |
14036 KB |
Output is correct |
11 |
Correct |
70 ms |
14024 KB |
Output is correct |
12 |
Correct |
11 ms |
14004 KB |
Output is correct |
13 |
Correct |
16 ms |
14036 KB |
Output is correct |
14 |
Correct |
13 ms |
14036 KB |
Output is correct |
15 |
Correct |
31 ms |
14036 KB |
Output is correct |
16 |
Correct |
423 ms |
14036 KB |
Output is correct |
17 |
Correct |
521 ms |
14036 KB |
Output is correct |
18 |
Correct |
209 ms |
14020 KB |
Output is correct |
19 |
Correct |
436 ms |
14036 KB |
Output is correct |
20 |
Correct |
696 ms |
14036 KB |
Output is correct |
21 |
Correct |
48 ms |
14036 KB |
Output is correct |
22 |
Correct |
51 ms |
14036 KB |
Output is correct |
23 |
Runtime error |
18 ms |
28244 KB |
Execution killed with signal 6 |
24 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
14024 KB |
Output is correct |
2 |
Runtime error |
17 ms |
28244 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
14044 KB |
Output is correct |
2 |
Correct |
14 ms |
14048 KB |
Output is correct |
3 |
Correct |
10 ms |
14036 KB |
Output is correct |
4 |
Correct |
36 ms |
14036 KB |
Output is correct |
5 |
Correct |
437 ms |
14024 KB |
Output is correct |
6 |
Correct |
455 ms |
14036 KB |
Output is correct |
7 |
Correct |
236 ms |
14036 KB |
Output is correct |
8 |
Correct |
422 ms |
14056 KB |
Output is correct |
9 |
Correct |
713 ms |
14036 KB |
Output is correct |
10 |
Correct |
43 ms |
14036 KB |
Output is correct |
11 |
Correct |
70 ms |
14024 KB |
Output is correct |
12 |
Correct |
11 ms |
14004 KB |
Output is correct |
13 |
Correct |
16 ms |
14036 KB |
Output is correct |
14 |
Correct |
13 ms |
14036 KB |
Output is correct |
15 |
Correct |
31 ms |
14036 KB |
Output is correct |
16 |
Correct |
423 ms |
14036 KB |
Output is correct |
17 |
Correct |
521 ms |
14036 KB |
Output is correct |
18 |
Correct |
209 ms |
14020 KB |
Output is correct |
19 |
Correct |
436 ms |
14036 KB |
Output is correct |
20 |
Correct |
696 ms |
14036 KB |
Output is correct |
21 |
Correct |
48 ms |
14036 KB |
Output is correct |
22 |
Correct |
51 ms |
14036 KB |
Output is correct |
23 |
Runtime error |
18 ms |
28244 KB |
Execution killed with signal 6 |
24 |
Halted |
0 ms |
0 KB |
- |