#include <iostream>
#include <vector>
#include "stdio.h"
#pragma GCC optimize("O1")
#pragma GCC optimize("O2")
#pragma GCC optimize("O3")
#pragma GCC optimize("Os")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
// #define int long long
long long const LLINF = 1e9 + 9;
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, 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);
} else if(i - 1 - m < 0){
y.push_back(-(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;
}
Compilation message
vault.cpp: In function 'int main()':
vault.cpp:28:9: warning: unused variable 'smn' [-Wunused-variable]
28 | int smn = 0, smf = 0;
| ^~~
vault.cpp:28:18: warning: unused variable 'smf' [-Wunused-variable]
28 | int smn = 0, smf = 0;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
4180 KB |
Output is correct |
2 |
Correct |
25 ms |
4180 KB |
Output is correct |
3 |
Correct |
19 ms |
4160 KB |
Output is correct |
4 |
Correct |
145 ms |
4264 KB |
Output is correct |
5 |
Correct |
2 ms |
4180 KB |
Output is correct |
6 |
Execution timed out |
5028 ms |
4180 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
4180 KB |
Output is correct |
2 |
Correct |
25 ms |
4180 KB |
Output is correct |
3 |
Correct |
19 ms |
4160 KB |
Output is correct |
4 |
Correct |
145 ms |
4264 KB |
Output is correct |
5 |
Correct |
2 ms |
4180 KB |
Output is correct |
6 |
Execution timed out |
5028 ms |
4180 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
170 ms |
4268 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4180 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
170 ms |
4268 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4180 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
170 ms |
4268 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4180 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
4180 KB |
Output is correct |
2 |
Correct |
25 ms |
4180 KB |
Output is correct |
3 |
Correct |
19 ms |
4160 KB |
Output is correct |
4 |
Correct |
145 ms |
4264 KB |
Output is correct |
5 |
Correct |
2 ms |
4180 KB |
Output is correct |
6 |
Execution timed out |
5028 ms |
4180 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
170 ms |
4268 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4180 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
4180 KB |
Output is correct |
2 |
Correct |
25 ms |
4180 KB |
Output is correct |
3 |
Correct |
19 ms |
4160 KB |
Output is correct |
4 |
Correct |
145 ms |
4264 KB |
Output is correct |
5 |
Correct |
2 ms |
4180 KB |
Output is correct |
6 |
Execution timed out |
5028 ms |
4180 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
170 ms |
4268 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4180 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
4180 KB |
Output is correct |
2 |
Correct |
25 ms |
4180 KB |
Output is correct |
3 |
Correct |
19 ms |
4160 KB |
Output is correct |
4 |
Correct |
145 ms |
4264 KB |
Output is correct |
5 |
Correct |
2 ms |
4180 KB |
Output is correct |
6 |
Execution timed out |
5028 ms |
4180 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |