#include<bits/stdc++.h>
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T>
using matrix = vector<vector<T>>;
const int INF = 1<<30;
const int MAXVAL = 505050;
struct smartvec{
vector<int> dp;
smartvec(){
dp = vector<int>(2*MAXVAL+1,-INF);
}
int& operator[](int id){
return dp[id+MAXVAL];
}
};
int main() {
cin.tie(0)->sync_with_stdio(0);
ll m, l;
cin >> m >> l;
if(abs(l) >= MAXVAL){
cout << "impossible\n";
return 0;
}
vector<pll> v;
for(int i = -m; i <= m; i++){
int in;
cin >> in;
for(int bit = 0; in; bit++){
int ct = min(1<<bit,in);
v.push_back({i*ct,ct});
in-=ct;
}
}
smartvec dp;
dp[0] = 0;
for(pii i : v){
if(i.ff >= 0){
for(int x = MAXVAL-1; x >= -MAXVAL+i.ff; x--){
dp[x] = max(dp[x],dp[x-i.ff]+i.ss);
}
} else {
for(int x = -MAXVAL; x < MAXVAL+i.ff; x++){
dp[x] = max(dp[x],dp[x-i.ff]+i.ss);
}
}
// cout << "iteracao " << i.ff << ' ' << i.ss << "=>" << endl;
// for(int i = -l; i <= l; i++){
// cout << i << ": " << dp[i] << endl;
// }
}
if(dp[l] >= 0){
cout << dp[l] << '\n';
} else cout << "impossible\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
4180 KB |
Output is correct |
2 |
Correct |
8 ms |
4180 KB |
Output is correct |
3 |
Correct |
5 ms |
4180 KB |
Output is correct |
4 |
Correct |
27 ms |
4180 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
408 ms |
4180 KB |
Output is correct |
7 |
Correct |
182 ms |
4180 KB |
Output is correct |
8 |
Correct |
396 ms |
4180 KB |
Output is correct |
9 |
Correct |
489 ms |
4308 KB |
Output is correct |
10 |
Correct |
16 ms |
4180 KB |
Output is correct |
11 |
Correct |
19 ms |
4180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
4180 KB |
Output is correct |
2 |
Correct |
8 ms |
4180 KB |
Output is correct |
3 |
Correct |
5 ms |
4180 KB |
Output is correct |
4 |
Correct |
27 ms |
4180 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
408 ms |
4180 KB |
Output is correct |
7 |
Correct |
182 ms |
4180 KB |
Output is correct |
8 |
Correct |
396 ms |
4180 KB |
Output is correct |
9 |
Correct |
489 ms |
4308 KB |
Output is correct |
10 |
Correct |
16 ms |
4180 KB |
Output is correct |
11 |
Correct |
19 ms |
4180 KB |
Output is correct |
12 |
Correct |
13 ms |
4180 KB |
Output is correct |
13 |
Correct |
8 ms |
4180 KB |
Output is correct |
14 |
Correct |
4 ms |
4180 KB |
Output is correct |
15 |
Correct |
27 ms |
4180 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
402 ms |
4180 KB |
Output is correct |
18 |
Correct |
163 ms |
4180 KB |
Output is correct |
19 |
Correct |
425 ms |
4180 KB |
Output is correct |
20 |
Correct |
493 ms |
4308 KB |
Output is correct |
21 |
Correct |
16 ms |
4180 KB |
Output is correct |
22 |
Correct |
16 ms |
4180 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
926 ms |
4308 KB |
Output is correct |
25 |
Correct |
343 ms |
4180 KB |
Output is correct |
26 |
Correct |
1199 ms |
4308 KB |
Output is correct |
27 |
Correct |
1127 ms |
4308 KB |
Output is correct |
28 |
Correct |
18 ms |
4180 KB |
Output is correct |
29 |
Correct |
24 ms |
4180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
4180 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
4180 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
4180 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
4180 KB |
Output is correct |
2 |
Correct |
8 ms |
4180 KB |
Output is correct |
3 |
Correct |
5 ms |
4180 KB |
Output is correct |
4 |
Correct |
27 ms |
4180 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
408 ms |
4180 KB |
Output is correct |
7 |
Correct |
182 ms |
4180 KB |
Output is correct |
8 |
Correct |
396 ms |
4180 KB |
Output is correct |
9 |
Correct |
489 ms |
4308 KB |
Output is correct |
10 |
Correct |
16 ms |
4180 KB |
Output is correct |
11 |
Correct |
19 ms |
4180 KB |
Output is correct |
12 |
Correct |
28 ms |
4180 KB |
Output is correct |
13 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
4180 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
4180 KB |
Output is correct |
2 |
Correct |
8 ms |
4180 KB |
Output is correct |
3 |
Correct |
5 ms |
4180 KB |
Output is correct |
4 |
Correct |
27 ms |
4180 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
408 ms |
4180 KB |
Output is correct |
7 |
Correct |
182 ms |
4180 KB |
Output is correct |
8 |
Correct |
396 ms |
4180 KB |
Output is correct |
9 |
Correct |
489 ms |
4308 KB |
Output is correct |
10 |
Correct |
16 ms |
4180 KB |
Output is correct |
11 |
Correct |
19 ms |
4180 KB |
Output is correct |
12 |
Correct |
13 ms |
4180 KB |
Output is correct |
13 |
Correct |
8 ms |
4180 KB |
Output is correct |
14 |
Correct |
4 ms |
4180 KB |
Output is correct |
15 |
Correct |
27 ms |
4180 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
402 ms |
4180 KB |
Output is correct |
18 |
Correct |
163 ms |
4180 KB |
Output is correct |
19 |
Correct |
425 ms |
4180 KB |
Output is correct |
20 |
Correct |
493 ms |
4308 KB |
Output is correct |
21 |
Correct |
16 ms |
4180 KB |
Output is correct |
22 |
Correct |
16 ms |
4180 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
926 ms |
4308 KB |
Output is correct |
25 |
Correct |
343 ms |
4180 KB |
Output is correct |
26 |
Correct |
1199 ms |
4308 KB |
Output is correct |
27 |
Correct |
1127 ms |
4308 KB |
Output is correct |
28 |
Correct |
18 ms |
4180 KB |
Output is correct |
29 |
Correct |
24 ms |
4180 KB |
Output is correct |
30 |
Correct |
28 ms |
4180 KB |
Output is correct |
31 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
4180 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
4180 KB |
Output is correct |
2 |
Correct |
8 ms |
4180 KB |
Output is correct |
3 |
Correct |
5 ms |
4180 KB |
Output is correct |
4 |
Correct |
27 ms |
4180 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
408 ms |
4180 KB |
Output is correct |
7 |
Correct |
182 ms |
4180 KB |
Output is correct |
8 |
Correct |
396 ms |
4180 KB |
Output is correct |
9 |
Correct |
489 ms |
4308 KB |
Output is correct |
10 |
Correct |
16 ms |
4180 KB |
Output is correct |
11 |
Correct |
19 ms |
4180 KB |
Output is correct |
12 |
Correct |
13 ms |
4180 KB |
Output is correct |
13 |
Correct |
8 ms |
4180 KB |
Output is correct |
14 |
Correct |
4 ms |
4180 KB |
Output is correct |
15 |
Correct |
27 ms |
4180 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
402 ms |
4180 KB |
Output is correct |
18 |
Correct |
163 ms |
4180 KB |
Output is correct |
19 |
Correct |
425 ms |
4180 KB |
Output is correct |
20 |
Correct |
493 ms |
4308 KB |
Output is correct |
21 |
Correct |
16 ms |
4180 KB |
Output is correct |
22 |
Correct |
16 ms |
4180 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
926 ms |
4308 KB |
Output is correct |
25 |
Correct |
343 ms |
4180 KB |
Output is correct |
26 |
Correct |
1199 ms |
4308 KB |
Output is correct |
27 |
Correct |
1127 ms |
4308 KB |
Output is correct |
28 |
Correct |
18 ms |
4180 KB |
Output is correct |
29 |
Correct |
24 ms |
4180 KB |
Output is correct |
30 |
Correct |
28 ms |
4180 KB |
Output is correct |
31 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |