#include <iostream>
#include <vector>
#include "stdio.h"
using namespace std;
#define int long long
long long const LLINF = 8e18;
int const N = 800000;
int const ZER = 400000;
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, l; cin >> m >> l;
int smn = 0, smf = 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);
}
}
}
if(l > smn || l < smf){
cout << "impossible\n"; return 0;
}
vector <int> dp(N, -LLINF);
dp[ZER] = (int)z.size();
for(int t: x){
for(int i = N - 1; i >= 0; i--){
if(i - t >= 0 && dp[i - t] != -LLINF){
dp[i] = max(dp[i], dp[i - t] + 1);
}
}
}
for(int t: y){
for(int i = 0; i < N; i ++){
if(i - t < N && dp[i - t] != -LLINF){
dp[i] = max(dp[i], dp[i - t] + 1);
}
}
}
// for(int i = 0; i < N; i ++) cout << dp[i] << " ";
int ans = -LLINF;
for(int i = 0; i < N; i ++){
if(i - ZER == l){
ans = dp[i]; break;
}
}
if(ans == -LLINF){
cout << "impossible\n";
} else {
cout << ans << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
6484 KB |
Output is correct |
2 |
Correct |
9 ms |
6484 KB |
Output is correct |
3 |
Correct |
7 ms |
6484 KB |
Output is correct |
4 |
Correct |
33 ms |
6484 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1631 ms |
6612 KB |
Output is correct |
7 |
Correct |
621 ms |
6484 KB |
Output is correct |
8 |
Correct |
1614 ms |
6612 KB |
Output is correct |
9 |
Correct |
2893 ms |
6612 KB |
Output is correct |
10 |
Correct |
79 ms |
6484 KB |
Output is correct |
11 |
Correct |
68 ms |
6484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
6484 KB |
Output is correct |
2 |
Correct |
9 ms |
6484 KB |
Output is correct |
3 |
Correct |
7 ms |
6484 KB |
Output is correct |
4 |
Correct |
33 ms |
6484 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1631 ms |
6612 KB |
Output is correct |
7 |
Correct |
621 ms |
6484 KB |
Output is correct |
8 |
Correct |
1614 ms |
6612 KB |
Output is correct |
9 |
Correct |
2893 ms |
6612 KB |
Output is correct |
10 |
Correct |
79 ms |
6484 KB |
Output is correct |
11 |
Correct |
68 ms |
6484 KB |
Output is correct |
12 |
Correct |
9 ms |
6484 KB |
Output is correct |
13 |
Correct |
7 ms |
6484 KB |
Output is correct |
14 |
Correct |
7 ms |
6484 KB |
Output is correct |
15 |
Correct |
46 ms |
6484 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1586 ms |
6612 KB |
Output is correct |
18 |
Correct |
628 ms |
6484 KB |
Output is correct |
19 |
Correct |
1488 ms |
6612 KB |
Output is correct |
20 |
Correct |
2938 ms |
6612 KB |
Output is correct |
21 |
Correct |
72 ms |
6484 KB |
Output is correct |
22 |
Correct |
55 ms |
6520 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Execution timed out |
5048 ms |
6740 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
6484 KB |
Output is correct |
2 |
Runtime error |
515 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
6484 KB |
Output is correct |
2 |
Runtime error |
515 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
6484 KB |
Output is correct |
2 |
Runtime error |
515 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
6484 KB |
Output is correct |
2 |
Correct |
9 ms |
6484 KB |
Output is correct |
3 |
Correct |
7 ms |
6484 KB |
Output is correct |
4 |
Correct |
33 ms |
6484 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1631 ms |
6612 KB |
Output is correct |
7 |
Correct |
621 ms |
6484 KB |
Output is correct |
8 |
Correct |
1614 ms |
6612 KB |
Output is correct |
9 |
Correct |
2893 ms |
6612 KB |
Output is correct |
10 |
Correct |
79 ms |
6484 KB |
Output is correct |
11 |
Correct |
68 ms |
6484 KB |
Output is correct |
12 |
Correct |
42 ms |
6484 KB |
Output is correct |
13 |
Runtime error |
515 ms |
524288 KB |
Execution killed with signal 9 |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
6484 KB |
Output is correct |
2 |
Runtime error |
515 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
6484 KB |
Output is correct |
2 |
Correct |
9 ms |
6484 KB |
Output is correct |
3 |
Correct |
7 ms |
6484 KB |
Output is correct |
4 |
Correct |
33 ms |
6484 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1631 ms |
6612 KB |
Output is correct |
7 |
Correct |
621 ms |
6484 KB |
Output is correct |
8 |
Correct |
1614 ms |
6612 KB |
Output is correct |
9 |
Correct |
2893 ms |
6612 KB |
Output is correct |
10 |
Correct |
79 ms |
6484 KB |
Output is correct |
11 |
Correct |
68 ms |
6484 KB |
Output is correct |
12 |
Correct |
9 ms |
6484 KB |
Output is correct |
13 |
Correct |
7 ms |
6484 KB |
Output is correct |
14 |
Correct |
7 ms |
6484 KB |
Output is correct |
15 |
Correct |
46 ms |
6484 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1586 ms |
6612 KB |
Output is correct |
18 |
Correct |
628 ms |
6484 KB |
Output is correct |
19 |
Correct |
1488 ms |
6612 KB |
Output is correct |
20 |
Correct |
2938 ms |
6612 KB |
Output is correct |
21 |
Correct |
72 ms |
6484 KB |
Output is correct |
22 |
Correct |
55 ms |
6520 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Execution timed out |
5048 ms |
6740 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
6484 KB |
Output is correct |
2 |
Runtime error |
515 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
6484 KB |
Output is correct |
2 |
Correct |
9 ms |
6484 KB |
Output is correct |
3 |
Correct |
7 ms |
6484 KB |
Output is correct |
4 |
Correct |
33 ms |
6484 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1631 ms |
6612 KB |
Output is correct |
7 |
Correct |
621 ms |
6484 KB |
Output is correct |
8 |
Correct |
1614 ms |
6612 KB |
Output is correct |
9 |
Correct |
2893 ms |
6612 KB |
Output is correct |
10 |
Correct |
79 ms |
6484 KB |
Output is correct |
11 |
Correct |
68 ms |
6484 KB |
Output is correct |
12 |
Correct |
9 ms |
6484 KB |
Output is correct |
13 |
Correct |
7 ms |
6484 KB |
Output is correct |
14 |
Correct |
7 ms |
6484 KB |
Output is correct |
15 |
Correct |
46 ms |
6484 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1586 ms |
6612 KB |
Output is correct |
18 |
Correct |
628 ms |
6484 KB |
Output is correct |
19 |
Correct |
1488 ms |
6612 KB |
Output is correct |
20 |
Correct |
2938 ms |
6612 KB |
Output is correct |
21 |
Correct |
72 ms |
6484 KB |
Output is correct |
22 |
Correct |
55 ms |
6520 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Execution timed out |
5048 ms |
6740 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |