#include <iostream>
#include <vector>
#include "stdio.h"
using namespace std;
// #define int long long
int const LLINF = 1e9 + 1;
int const N = (10000 * 101) / 2 + 9;
int const ZER = 300000;
signed main(){
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#ifdef WTF
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
int m;
long long l; cin >> m >> l;
int smn = 0, smf = 0;
if (l >= N || l < -N){
cout << "impossible\n";
return 0;
}
vector <int> a(2 * m + 2), x, y, z;
for(int i = 1; i <= 2 * m + 1; i ++){
cin >> a[i];
int K = a[i];
while(K --){
if(i - 1 - m >= 0){
x.push_back(i - 1 - m);
smn += i - 1 - m;
} else if(i - 1 - m < 0){
y.push_back(-(i - 1 - m));
smf += i - 1 - m;
} else {
z.push_back(i - 1 - m);
}
}
}
vector <int> dp1(N, -LLINF), dp2(N, -LLINF);
dp1[0] = 0;
dp2[0] = 0;
for(int k: x){
for(int i = N - 1; i >= k; i --){
dp1[i] = max(dp1[i], dp1[i - k] + 1);
}
}
// for(int i = 0; i < N; i ++){
// cout << dp1[i] << " ";
// }
// cout << "\n";
for(int k: y){
for(int i = N - 1; i >= k; i --){
dp2[i] = max(dp2[i], dp2[i - k] + 1);
}
}
int ans = -LLINF;
if(l >= 0){
for(int i = l; i < N; i ++){
int j = i - l;
ans = max(ans, dp1[i] + dp2[j]);
}
} else {
l = -l;
for(int i = l; i < N; i ++){
int j = i - l;
ans = max(ans, dp2[i] + dp1[j]);
}
}
if(ans < 0){
cout << "impossible\n";
} else {
cout << ans << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
4180 KB |
Output is correct |
2 |
Correct |
7 ms |
4180 KB |
Output is correct |
3 |
Correct |
7 ms |
4180 KB |
Output is correct |
4 |
Correct |
36 ms |
4264 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1191 ms |
4308 KB |
Output is correct |
7 |
Correct |
444 ms |
4288 KB |
Output is correct |
8 |
Correct |
1126 ms |
4288 KB |
Output is correct |
9 |
Correct |
2096 ms |
4308 KB |
Output is correct |
10 |
Correct |
49 ms |
4180 KB |
Output is correct |
11 |
Correct |
39 ms |
4180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
4180 KB |
Output is correct |
2 |
Correct |
7 ms |
4180 KB |
Output is correct |
3 |
Correct |
7 ms |
4180 KB |
Output is correct |
4 |
Correct |
36 ms |
4264 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1191 ms |
4308 KB |
Output is correct |
7 |
Correct |
444 ms |
4288 KB |
Output is correct |
8 |
Correct |
1126 ms |
4288 KB |
Output is correct |
9 |
Correct |
2096 ms |
4308 KB |
Output is correct |
10 |
Correct |
49 ms |
4180 KB |
Output is correct |
11 |
Correct |
39 ms |
4180 KB |
Output is correct |
12 |
Correct |
10 ms |
4236 KB |
Output is correct |
13 |
Correct |
8 ms |
4180 KB |
Output is correct |
14 |
Correct |
8 ms |
4284 KB |
Output is correct |
15 |
Correct |
32 ms |
4180 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1167 ms |
4308 KB |
Output is correct |
18 |
Correct |
496 ms |
4280 KB |
Output is correct |
19 |
Correct |
1085 ms |
4308 KB |
Output is correct |
20 |
Correct |
2057 ms |
4428 KB |
Output is correct |
21 |
Correct |
49 ms |
4180 KB |
Output is correct |
22 |
Correct |
38 ms |
4264 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
4246 ms |
4360 KB |
Output is correct |
25 |
Correct |
1476 ms |
4308 KB |
Output is correct |
26 |
Execution timed out |
5033 ms |
4436 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
4180 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
4180 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
4180 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
4180 KB |
Output is correct |
2 |
Correct |
7 ms |
4180 KB |
Output is correct |
3 |
Correct |
7 ms |
4180 KB |
Output is correct |
4 |
Correct |
36 ms |
4264 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1191 ms |
4308 KB |
Output is correct |
7 |
Correct |
444 ms |
4288 KB |
Output is correct |
8 |
Correct |
1126 ms |
4288 KB |
Output is correct |
9 |
Correct |
2096 ms |
4308 KB |
Output is correct |
10 |
Correct |
49 ms |
4180 KB |
Output is correct |
11 |
Correct |
39 ms |
4180 KB |
Output is correct |
12 |
Correct |
30 ms |
4180 KB |
Output is correct |
13 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
4180 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
4180 KB |
Output is correct |
2 |
Correct |
7 ms |
4180 KB |
Output is correct |
3 |
Correct |
7 ms |
4180 KB |
Output is correct |
4 |
Correct |
36 ms |
4264 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1191 ms |
4308 KB |
Output is correct |
7 |
Correct |
444 ms |
4288 KB |
Output is correct |
8 |
Correct |
1126 ms |
4288 KB |
Output is correct |
9 |
Correct |
2096 ms |
4308 KB |
Output is correct |
10 |
Correct |
49 ms |
4180 KB |
Output is correct |
11 |
Correct |
39 ms |
4180 KB |
Output is correct |
12 |
Correct |
10 ms |
4236 KB |
Output is correct |
13 |
Correct |
8 ms |
4180 KB |
Output is correct |
14 |
Correct |
8 ms |
4284 KB |
Output is correct |
15 |
Correct |
32 ms |
4180 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1167 ms |
4308 KB |
Output is correct |
18 |
Correct |
496 ms |
4280 KB |
Output is correct |
19 |
Correct |
1085 ms |
4308 KB |
Output is correct |
20 |
Correct |
2057 ms |
4428 KB |
Output is correct |
21 |
Correct |
49 ms |
4180 KB |
Output is correct |
22 |
Correct |
38 ms |
4264 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
4246 ms |
4360 KB |
Output is correct |
25 |
Correct |
1476 ms |
4308 KB |
Output is correct |
26 |
Execution timed out |
5033 ms |
4436 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
4180 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
4180 KB |
Output is correct |
2 |
Correct |
7 ms |
4180 KB |
Output is correct |
3 |
Correct |
7 ms |
4180 KB |
Output is correct |
4 |
Correct |
36 ms |
4264 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1191 ms |
4308 KB |
Output is correct |
7 |
Correct |
444 ms |
4288 KB |
Output is correct |
8 |
Correct |
1126 ms |
4288 KB |
Output is correct |
9 |
Correct |
2096 ms |
4308 KB |
Output is correct |
10 |
Correct |
49 ms |
4180 KB |
Output is correct |
11 |
Correct |
39 ms |
4180 KB |
Output is correct |
12 |
Correct |
10 ms |
4236 KB |
Output is correct |
13 |
Correct |
8 ms |
4180 KB |
Output is correct |
14 |
Correct |
8 ms |
4284 KB |
Output is correct |
15 |
Correct |
32 ms |
4180 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1167 ms |
4308 KB |
Output is correct |
18 |
Correct |
496 ms |
4280 KB |
Output is correct |
19 |
Correct |
1085 ms |
4308 KB |
Output is correct |
20 |
Correct |
2057 ms |
4428 KB |
Output is correct |
21 |
Correct |
49 ms |
4180 KB |
Output is correct |
22 |
Correct |
38 ms |
4264 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
4246 ms |
4360 KB |
Output is correct |
25 |
Correct |
1476 ms |
4308 KB |
Output is correct |
26 |
Execution timed out |
5033 ms |
4436 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |