//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
while (l != r) cout << *l << " ", l++;
cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 1100005
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
const int inf = 1<<30;
int dp[2][maxn];
int main() {
io
int m;
ll L;
cin >> m >> L;
vector<ll> a(2*m+1);
ll mins = 0;
for (int i = 0;i < 2*m+1;i++) {
cin >> a[i];
if (i < m) mins += a[i] * (i - m);
}
for (int i = 0;i < maxn;i++) dp[0][i] = dp[1][i] = -inf;
dp[0][-mins] = 0;
dp[1][-mins] = 0;
for (int i = 0;i < 2*m+1;i++) {
ll cnt = 1;
vector<int> num;
while (a[i] >= cnt) {
num.push_back(cnt);
a[i] -= cnt;
cnt <<= 1;
}
if (a[i] > 0) num.push_back(a[i]);
for (int p:num) {
for (int j = 0;j < maxn;j++) {
int val = j + p * (i-m);
if (val >= 0 && val < maxn) dp[1][val] = max(dp[1][val], dp[0][j] + p);
}
for (int j = 0;j < maxn;j++) dp[0][j] = dp[1][j];
}
}
if (L - mins >= maxn || L - mins < 0 || dp[0][L - mins] < 0) cout << "impossible\n";
else cout << dp[0][L - mins] << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
8916 KB |
Output is correct |
2 |
Correct |
16 ms |
8916 KB |
Output is correct |
3 |
Correct |
9 ms |
8916 KB |
Output is correct |
4 |
Correct |
56 ms |
8916 KB |
Output is correct |
5 |
Correct |
784 ms |
8916 KB |
Output is correct |
6 |
Correct |
752 ms |
8916 KB |
Output is correct |
7 |
Correct |
330 ms |
8916 KB |
Output is correct |
8 |
Correct |
769 ms |
8916 KB |
Output is correct |
9 |
Correct |
960 ms |
8916 KB |
Output is correct |
10 |
Correct |
29 ms |
8916 KB |
Output is correct |
11 |
Correct |
30 ms |
8916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
8916 KB |
Output is correct |
2 |
Correct |
16 ms |
8916 KB |
Output is correct |
3 |
Correct |
9 ms |
8916 KB |
Output is correct |
4 |
Correct |
56 ms |
8916 KB |
Output is correct |
5 |
Correct |
784 ms |
8916 KB |
Output is correct |
6 |
Correct |
752 ms |
8916 KB |
Output is correct |
7 |
Correct |
330 ms |
8916 KB |
Output is correct |
8 |
Correct |
769 ms |
8916 KB |
Output is correct |
9 |
Correct |
960 ms |
8916 KB |
Output is correct |
10 |
Correct |
29 ms |
8916 KB |
Output is correct |
11 |
Correct |
30 ms |
8916 KB |
Output is correct |
12 |
Correct |
18 ms |
8932 KB |
Output is correct |
13 |
Correct |
16 ms |
8932 KB |
Output is correct |
14 |
Correct |
9 ms |
8916 KB |
Output is correct |
15 |
Correct |
51 ms |
8916 KB |
Output is correct |
16 |
Correct |
771 ms |
8916 KB |
Output is correct |
17 |
Correct |
859 ms |
8916 KB |
Output is correct |
18 |
Correct |
342 ms |
8916 KB |
Output is correct |
19 |
Correct |
765 ms |
8916 KB |
Output is correct |
20 |
Correct |
985 ms |
8916 KB |
Output is correct |
21 |
Correct |
54 ms |
8916 KB |
Output is correct |
22 |
Correct |
41 ms |
8916 KB |
Output is correct |
23 |
Correct |
1810 ms |
8916 KB |
Output is correct |
24 |
Correct |
1774 ms |
8916 KB |
Output is correct |
25 |
Correct |
843 ms |
8916 KB |
Output is correct |
26 |
Correct |
2194 ms |
8916 KB |
Output is correct |
27 |
Correct |
2231 ms |
8908 KB |
Output is correct |
28 |
Correct |
35 ms |
8916 KB |
Output is correct |
29 |
Correct |
45 ms |
8916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
8916 KB |
Output is correct |
2 |
Incorrect |
906 ms |
8916 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
8916 KB |
Output is correct |
2 |
Incorrect |
906 ms |
8916 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
8916 KB |
Output is correct |
2 |
Incorrect |
906 ms |
8916 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
8916 KB |
Output is correct |
2 |
Correct |
16 ms |
8916 KB |
Output is correct |
3 |
Correct |
9 ms |
8916 KB |
Output is correct |
4 |
Correct |
56 ms |
8916 KB |
Output is correct |
5 |
Correct |
784 ms |
8916 KB |
Output is correct |
6 |
Correct |
752 ms |
8916 KB |
Output is correct |
7 |
Correct |
330 ms |
8916 KB |
Output is correct |
8 |
Correct |
769 ms |
8916 KB |
Output is correct |
9 |
Correct |
960 ms |
8916 KB |
Output is correct |
10 |
Correct |
29 ms |
8916 KB |
Output is correct |
11 |
Correct |
30 ms |
8916 KB |
Output is correct |
12 |
Correct |
52 ms |
8916 KB |
Output is correct |
13 |
Incorrect |
906 ms |
8916 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
8916 KB |
Output is correct |
2 |
Incorrect |
906 ms |
8916 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
8916 KB |
Output is correct |
2 |
Correct |
16 ms |
8916 KB |
Output is correct |
3 |
Correct |
9 ms |
8916 KB |
Output is correct |
4 |
Correct |
56 ms |
8916 KB |
Output is correct |
5 |
Correct |
784 ms |
8916 KB |
Output is correct |
6 |
Correct |
752 ms |
8916 KB |
Output is correct |
7 |
Correct |
330 ms |
8916 KB |
Output is correct |
8 |
Correct |
769 ms |
8916 KB |
Output is correct |
9 |
Correct |
960 ms |
8916 KB |
Output is correct |
10 |
Correct |
29 ms |
8916 KB |
Output is correct |
11 |
Correct |
30 ms |
8916 KB |
Output is correct |
12 |
Correct |
18 ms |
8932 KB |
Output is correct |
13 |
Correct |
16 ms |
8932 KB |
Output is correct |
14 |
Correct |
9 ms |
8916 KB |
Output is correct |
15 |
Correct |
51 ms |
8916 KB |
Output is correct |
16 |
Correct |
771 ms |
8916 KB |
Output is correct |
17 |
Correct |
859 ms |
8916 KB |
Output is correct |
18 |
Correct |
342 ms |
8916 KB |
Output is correct |
19 |
Correct |
765 ms |
8916 KB |
Output is correct |
20 |
Correct |
985 ms |
8916 KB |
Output is correct |
21 |
Correct |
54 ms |
8916 KB |
Output is correct |
22 |
Correct |
41 ms |
8916 KB |
Output is correct |
23 |
Correct |
1810 ms |
8916 KB |
Output is correct |
24 |
Correct |
1774 ms |
8916 KB |
Output is correct |
25 |
Correct |
843 ms |
8916 KB |
Output is correct |
26 |
Correct |
2194 ms |
8916 KB |
Output is correct |
27 |
Correct |
2231 ms |
8908 KB |
Output is correct |
28 |
Correct |
35 ms |
8916 KB |
Output is correct |
29 |
Correct |
45 ms |
8916 KB |
Output is correct |
30 |
Correct |
52 ms |
8916 KB |
Output is correct |
31 |
Incorrect |
906 ms |
8916 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
8916 KB |
Output is correct |
2 |
Incorrect |
906 ms |
8916 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
8916 KB |
Output is correct |
2 |
Correct |
16 ms |
8916 KB |
Output is correct |
3 |
Correct |
9 ms |
8916 KB |
Output is correct |
4 |
Correct |
56 ms |
8916 KB |
Output is correct |
5 |
Correct |
784 ms |
8916 KB |
Output is correct |
6 |
Correct |
752 ms |
8916 KB |
Output is correct |
7 |
Correct |
330 ms |
8916 KB |
Output is correct |
8 |
Correct |
769 ms |
8916 KB |
Output is correct |
9 |
Correct |
960 ms |
8916 KB |
Output is correct |
10 |
Correct |
29 ms |
8916 KB |
Output is correct |
11 |
Correct |
30 ms |
8916 KB |
Output is correct |
12 |
Correct |
18 ms |
8932 KB |
Output is correct |
13 |
Correct |
16 ms |
8932 KB |
Output is correct |
14 |
Correct |
9 ms |
8916 KB |
Output is correct |
15 |
Correct |
51 ms |
8916 KB |
Output is correct |
16 |
Correct |
771 ms |
8916 KB |
Output is correct |
17 |
Correct |
859 ms |
8916 KB |
Output is correct |
18 |
Correct |
342 ms |
8916 KB |
Output is correct |
19 |
Correct |
765 ms |
8916 KB |
Output is correct |
20 |
Correct |
985 ms |
8916 KB |
Output is correct |
21 |
Correct |
54 ms |
8916 KB |
Output is correct |
22 |
Correct |
41 ms |
8916 KB |
Output is correct |
23 |
Correct |
1810 ms |
8916 KB |
Output is correct |
24 |
Correct |
1774 ms |
8916 KB |
Output is correct |
25 |
Correct |
843 ms |
8916 KB |
Output is correct |
26 |
Correct |
2194 ms |
8916 KB |
Output is correct |
27 |
Correct |
2231 ms |
8908 KB |
Output is correct |
28 |
Correct |
35 ms |
8916 KB |
Output is correct |
29 |
Correct |
45 ms |
8916 KB |
Output is correct |
30 |
Correct |
52 ms |
8916 KB |
Output is correct |
31 |
Incorrect |
906 ms |
8916 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |