#include <iostream>
#include <vector>
#include "stdio.h"
using namespace std;
#define int long long
int const LLINF = 1e9 + 9;
int const N = (10000 * 101) / 2 + 2;
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;
vector <int> x, y, z;
for(int i = -m; i <= m; i ++){
int K; cin >> K;
while(K --){
if(i >= 0){
x.push_back(i);
} else {
y.push_back(-i);
}
}
}
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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8148 KB |
Output is correct |
2 |
Correct |
8 ms |
8148 KB |
Output is correct |
3 |
Correct |
7 ms |
8184 KB |
Output is correct |
4 |
Correct |
32 ms |
8204 KB |
Output is correct |
5 |
Correct |
1115 ms |
8276 KB |
Output is correct |
6 |
Correct |
1157 ms |
8396 KB |
Output is correct |
7 |
Correct |
475 ms |
8268 KB |
Output is correct |
8 |
Correct |
1232 ms |
8276 KB |
Output is correct |
9 |
Correct |
2200 ms |
8300 KB |
Output is correct |
10 |
Correct |
53 ms |
8148 KB |
Output is correct |
11 |
Correct |
47 ms |
8148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8148 KB |
Output is correct |
2 |
Correct |
8 ms |
8148 KB |
Output is correct |
3 |
Correct |
7 ms |
8184 KB |
Output is correct |
4 |
Correct |
32 ms |
8204 KB |
Output is correct |
5 |
Correct |
1115 ms |
8276 KB |
Output is correct |
6 |
Correct |
1157 ms |
8396 KB |
Output is correct |
7 |
Correct |
475 ms |
8268 KB |
Output is correct |
8 |
Correct |
1232 ms |
8276 KB |
Output is correct |
9 |
Correct |
2200 ms |
8300 KB |
Output is correct |
10 |
Correct |
53 ms |
8148 KB |
Output is correct |
11 |
Correct |
47 ms |
8148 KB |
Output is correct |
12 |
Correct |
9 ms |
8148 KB |
Output is correct |
13 |
Correct |
10 ms |
8240 KB |
Output is correct |
14 |
Correct |
7 ms |
8240 KB |
Output is correct |
15 |
Correct |
33 ms |
8148 KB |
Output is correct |
16 |
Correct |
1224 ms |
8276 KB |
Output is correct |
17 |
Correct |
1394 ms |
8276 KB |
Output is correct |
18 |
Correct |
552 ms |
8240 KB |
Output is correct |
19 |
Correct |
1216 ms |
8276 KB |
Output is correct |
20 |
Correct |
2542 ms |
8296 KB |
Output is correct |
21 |
Correct |
87 ms |
8224 KB |
Output is correct |
22 |
Correct |
48 ms |
8224 KB |
Output is correct |
23 |
Correct |
4713 ms |
8372 KB |
Output is correct |
24 |
Correct |
4345 ms |
8368 KB |
Output is correct |
25 |
Correct |
1486 ms |
8276 KB |
Output is correct |
26 |
Execution timed out |
5046 ms |
8468 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
8148 KB |
Output is correct |
2 |
Runtime error |
407 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
8148 KB |
Output is correct |
2 |
Runtime error |
407 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
8148 KB |
Output is correct |
2 |
Runtime error |
407 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8148 KB |
Output is correct |
2 |
Correct |
8 ms |
8148 KB |
Output is correct |
3 |
Correct |
7 ms |
8184 KB |
Output is correct |
4 |
Correct |
32 ms |
8204 KB |
Output is correct |
5 |
Correct |
1115 ms |
8276 KB |
Output is correct |
6 |
Correct |
1157 ms |
8396 KB |
Output is correct |
7 |
Correct |
475 ms |
8268 KB |
Output is correct |
8 |
Correct |
1232 ms |
8276 KB |
Output is correct |
9 |
Correct |
2200 ms |
8300 KB |
Output is correct |
10 |
Correct |
53 ms |
8148 KB |
Output is correct |
11 |
Correct |
47 ms |
8148 KB |
Output is correct |
12 |
Correct |
30 ms |
8148 KB |
Output is correct |
13 |
Runtime error |
407 ms |
524288 KB |
Execution killed with signal 9 |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
8148 KB |
Output is correct |
2 |
Runtime error |
407 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8148 KB |
Output is correct |
2 |
Correct |
8 ms |
8148 KB |
Output is correct |
3 |
Correct |
7 ms |
8184 KB |
Output is correct |
4 |
Correct |
32 ms |
8204 KB |
Output is correct |
5 |
Correct |
1115 ms |
8276 KB |
Output is correct |
6 |
Correct |
1157 ms |
8396 KB |
Output is correct |
7 |
Correct |
475 ms |
8268 KB |
Output is correct |
8 |
Correct |
1232 ms |
8276 KB |
Output is correct |
9 |
Correct |
2200 ms |
8300 KB |
Output is correct |
10 |
Correct |
53 ms |
8148 KB |
Output is correct |
11 |
Correct |
47 ms |
8148 KB |
Output is correct |
12 |
Correct |
9 ms |
8148 KB |
Output is correct |
13 |
Correct |
10 ms |
8240 KB |
Output is correct |
14 |
Correct |
7 ms |
8240 KB |
Output is correct |
15 |
Correct |
33 ms |
8148 KB |
Output is correct |
16 |
Correct |
1224 ms |
8276 KB |
Output is correct |
17 |
Correct |
1394 ms |
8276 KB |
Output is correct |
18 |
Correct |
552 ms |
8240 KB |
Output is correct |
19 |
Correct |
1216 ms |
8276 KB |
Output is correct |
20 |
Correct |
2542 ms |
8296 KB |
Output is correct |
21 |
Correct |
87 ms |
8224 KB |
Output is correct |
22 |
Correct |
48 ms |
8224 KB |
Output is correct |
23 |
Correct |
4713 ms |
8372 KB |
Output is correct |
24 |
Correct |
4345 ms |
8368 KB |
Output is correct |
25 |
Correct |
1486 ms |
8276 KB |
Output is correct |
26 |
Execution timed out |
5046 ms |
8468 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
8148 KB |
Output is correct |
2 |
Runtime error |
407 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8148 KB |
Output is correct |
2 |
Correct |
8 ms |
8148 KB |
Output is correct |
3 |
Correct |
7 ms |
8184 KB |
Output is correct |
4 |
Correct |
32 ms |
8204 KB |
Output is correct |
5 |
Correct |
1115 ms |
8276 KB |
Output is correct |
6 |
Correct |
1157 ms |
8396 KB |
Output is correct |
7 |
Correct |
475 ms |
8268 KB |
Output is correct |
8 |
Correct |
1232 ms |
8276 KB |
Output is correct |
9 |
Correct |
2200 ms |
8300 KB |
Output is correct |
10 |
Correct |
53 ms |
8148 KB |
Output is correct |
11 |
Correct |
47 ms |
8148 KB |
Output is correct |
12 |
Correct |
9 ms |
8148 KB |
Output is correct |
13 |
Correct |
10 ms |
8240 KB |
Output is correct |
14 |
Correct |
7 ms |
8240 KB |
Output is correct |
15 |
Correct |
33 ms |
8148 KB |
Output is correct |
16 |
Correct |
1224 ms |
8276 KB |
Output is correct |
17 |
Correct |
1394 ms |
8276 KB |
Output is correct |
18 |
Correct |
552 ms |
8240 KB |
Output is correct |
19 |
Correct |
1216 ms |
8276 KB |
Output is correct |
20 |
Correct |
2542 ms |
8296 KB |
Output is correct |
21 |
Correct |
87 ms |
8224 KB |
Output is correct |
22 |
Correct |
48 ms |
8224 KB |
Output is correct |
23 |
Correct |
4713 ms |
8372 KB |
Output is correct |
24 |
Correct |
4345 ms |
8368 KB |
Output is correct |
25 |
Correct |
1486 ms |
8276 KB |
Output is correct |
26 |
Execution timed out |
5046 ms |
8468 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |