#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define repa(i,a,b) for(int i = (a); i >= (b); i--)
#define pll pair<lli,lli>
#define MAX 1000000
lli m,l,res,ceros,a,b,c;
lli arr[2][102];
lli dp[2][MAX+2], usados[MAX+2], existe[2][MAX+2];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> m >> l;
repa(i,m,1) cin >> arr[0][i];
cin >> ceros;
rep(i,1,m) cin >> arr[1][i];
rep(id,0,1) {
existe[id][0] = true;
rep(i,1,m) {
rep(j,1,MAX) {
a = j-i;
usados[j] = 0;
if(a < 0) continue;
if (!existe[id][a]) continue;
if (usados[a] == arr[id][i]) continue; //podrai hacer un berak? segun yo no
b = dp[id][a]+1;
if (b > dp[id][j]) {
existe[id][j] = 1;
usados[j] = usados[a]+1;
dp[id][j] = b;
}
}
}
}
//rep(id,0,1) {
// debug(id);
// rep(i,0,15) {
// debugsl(i);
// debugsl(existe[id][i]);
// debug(dp[id][i]);
// }
//}
res = -1;
a = 0;
b = 0;
if (l < 0) a = l;
else b = l;
rep(i,0,MAX) {
if( (a+i) > MAX || (b+i) > MAX) break;
if(!existe[0][i+a] || !existe[1][i+b]) continue;
c = dp[0][i+a] + dp[1][i+b];
res = max(res,c);
}
if(res == -1) {
else cout << "impossible";
return 0;
}
res += ceros;
if(res == 0) cout << "impossible";
else cout << res;
return 0;
}
Compilation message
vault.cpp: In function 'int main()':
vault.cpp:75:9: error: expected '}' before 'else'
75 | else cout << "impossible";
| ^~~~
vault.cpp:74:19: note: to match this '{'
74 | if(res == -1) {
| ^
vault.cpp: At global scope:
vault.cpp:79:5: error: 'res' does not name a type
79 | res += ceros;
| ^~~
vault.cpp:80:5: error: expected unqualified-id before 'if'
80 | if(res == 0) cout << "impossible";
| ^~
vault.cpp:81:5: error: expected unqualified-id before 'else'
81 | else cout << res;
| ^~~~
vault.cpp:82:5: error: expected unqualified-id before 'return'
82 | return 0;
| ^~~~~~
vault.cpp:83:1: error: expected declaration before '}' token
83 | }
| ^