#include <bits/stdc++.h>
using namespace std;
#define int ll
#define ll long long
#define pii pair<ll, ll>
#define f first
#define s second
#define SZ(x) (int)((x).size())
#define ALL(x) (x).begin(), (x).end()
#define pb push_back
#define FOR(i,a,b) for (int i = a; i<b; ++i)
#define RREP(i,n) for (int i = n-1; i>=0;--i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define MX(a,b) a = max(a,b)
#define MN(a,b) a = min(a,b)
#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<"- ", _do(__VA_ARGS__)
template<typename T> void _do( T && x) {cerr<<x<<endl;}
template<typename T,typename ...S> void _do( T && x, S && ...y) {cerr<<x<<", "; _do(y...);}
#else
#define bug(...)
#define endl '\n'
#endif // BALBIT
ll amt[606];
ll taken[606];
const ll inf = 0x3f3f3f3f3f3f3f3f;
const int rng = 300 * 300 * 2;
ll bst[rng*2+4];
vector<ll> bd(ll x) {
// maybe i can min x ith rng or smth
vector<ll> re;
ll scale = 1;
while(x) {
if (x & 1) {
re.pb(scale); x-=1;
}else{
re.pb(scale); re.pb(scale); x-=2;
}
x/=2; scale *= 2;
}
return re;
}
void ASS(bool x) {
if (!x) while(1);
}
signed main(){
ios::sync_with_stdio(0), cin.tie(0);
bug(1,2);
// vector<int> hi = bd(23);
// for (int x : hi) cout<<x<<' ';
// return 0;
REP(i, rng*2+4) {
bst[i] = -inf;
}
int m; ll L;
cin>>m>>L;
ll tot = 0;
ll things= 0;
FOR(i,-m,m+1) {
cin>>amt[i+m];
tot += i * (amt[i+m]);
things += amt[i+m];
}
bug(tot, L);
if (tot < L) {
// flip everything
FOR(i,0,m+1) {
swap(amt[i+m], amt[-i+m]);
}
tot = -tot; L = -L;
}
FOR(i,-m,m+1) {
taken[i+m] = amt[i+m];
}
bug(tot,L);
for (int i = m; i>=1; --i) {
if (tot > L + rng) {
int need = (tot - (L+rng)-1) / i + 1; // ceiling
need = min(need, taken[i+m]);
taken[i+m] -= need; tot -= i * need; things -= need;
}
if (tot <= L+rng && tot >= L-rng) {
// MX(bst[tot-L+rng], things);
bug(tot, things);
while (taken[i+m] && (tot-i >= L-rng)) {
--taken[i+m]; tot -= i; --things;
bug(tot, things);
// MX(bst[tot-L+rng], things);
}
}
}
bug(tot, L, things);
MX(bst[tot-L+rng], things);
if (tot > L) {
// sad
cout<<"impossible"<<endl; return 0;
}
// FOR(j,-2*m,2*m+1) {
// bug(j, bst[j+rng]);
// }
FOR(i,1,m+1) {
if (amt[i+m] - taken[i+m]) {
// try adding stuff back
for (ll d : bd(amt[i+m] - taken[i+m])) {
if (i < 0) {
ASS(0);
}else{
RREP(j, rng*2+1 - d*i) {
MX(bst[j+d*i], bst[j]+d);
}
}
}
}
#ifdef BALBIT
// bug(i, taken[i+m], amt[i+m]);
// FOR(j,-2*m,2*m+1) {
// bug(j, bst[j+rng]);
// }
#endif
}
FOR(i,-m,m+1) {
if (i == 0) continue;
if (taken[i+m]) {
// try removing stuff
for (ll d : bd(taken[i+m])) {
if (i < 0) {
RREP(j, rng*2+1+d*i) {
if (j - d*i < 0) ASS(0);
if (j - d*i > rng*2) ASS(0);
MX(bst[j-d*i], bst[j]-d);
}
}else{
FOR(j, d*i, rng*2+1) {
if (j - d*i < 0) ASS(0);
if (j - d*i > rng*2) ASS(0);
MX(bst[j-d*i], bst[j]-d);
}
}
}
}
#ifdef BALBIT
// bug(i, taken[i+m], amt[i+m]);
// FOR(j,-m,m+1) {
// bug(j, bst[j+rng]);
// }
#endif
}
if (bst[rng] <= 0) cout<<"impossible"<<endl;
else cout<<bst[rng]<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3028 KB |
Output is correct |
2 |
Correct |
5 ms |
3028 KB |
Output is correct |
3 |
Correct |
3 ms |
3028 KB |
Output is correct |
4 |
Correct |
12 ms |
3028 KB |
Output is correct |
5 |
Runtime error |
4 ms |
6100 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3028 KB |
Output is correct |
2 |
Correct |
5 ms |
3028 KB |
Output is correct |
3 |
Correct |
3 ms |
3028 KB |
Output is correct |
4 |
Correct |
12 ms |
3028 KB |
Output is correct |
5 |
Runtime error |
4 ms |
6100 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
3028 KB |
Output is correct |
2 |
Correct |
159 ms |
3132 KB |
Output is correct |
3 |
Correct |
56 ms |
3148 KB |
Output is correct |
4 |
Correct |
138 ms |
3128 KB |
Output is correct |
5 |
Correct |
153 ms |
3132 KB |
Output is correct |
6 |
Correct |
91 ms |
3124 KB |
Output is correct |
7 |
Correct |
14 ms |
3028 KB |
Output is correct |
8 |
Correct |
11 ms |
3148 KB |
Output is correct |
9 |
Correct |
113 ms |
3132 KB |
Output is correct |
10 |
Correct |
99 ms |
3132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
3028 KB |
Output is correct |
2 |
Correct |
159 ms |
3132 KB |
Output is correct |
3 |
Correct |
56 ms |
3148 KB |
Output is correct |
4 |
Correct |
138 ms |
3128 KB |
Output is correct |
5 |
Correct |
153 ms |
3132 KB |
Output is correct |
6 |
Correct |
91 ms |
3124 KB |
Output is correct |
7 |
Correct |
14 ms |
3028 KB |
Output is correct |
8 |
Correct |
11 ms |
3148 KB |
Output is correct |
9 |
Correct |
113 ms |
3132 KB |
Output is correct |
10 |
Correct |
99 ms |
3132 KB |
Output is correct |
11 |
Correct |
7 ms |
3028 KB |
Output is correct |
12 |
Correct |
4 ms |
3028 KB |
Output is correct |
13 |
Correct |
4 ms |
3144 KB |
Output is correct |
14 |
Correct |
15 ms |
3148 KB |
Output is correct |
15 |
Correct |
149 ms |
3128 KB |
Output is correct |
16 |
Correct |
47 ms |
3144 KB |
Output is correct |
17 |
Correct |
135 ms |
3124 KB |
Output is correct |
18 |
Correct |
136 ms |
3128 KB |
Output is correct |
19 |
Correct |
84 ms |
3140 KB |
Output is correct |
20 |
Correct |
21 ms |
3028 KB |
Output is correct |
21 |
Correct |
12 ms |
3028 KB |
Output is correct |
22 |
Correct |
56 ms |
3124 KB |
Output is correct |
23 |
Correct |
93 ms |
3128 KB |
Output is correct |
24 |
Correct |
295 ms |
3124 KB |
Output is correct |
25 |
Correct |
86 ms |
3124 KB |
Output is correct |
26 |
Correct |
271 ms |
3128 KB |
Output is correct |
27 |
Correct |
189 ms |
3128 KB |
Output is correct |
28 |
Correct |
251 ms |
3132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
3028 KB |
Output is correct |
2 |
Correct |
159 ms |
3132 KB |
Output is correct |
3 |
Correct |
56 ms |
3148 KB |
Output is correct |
4 |
Correct |
138 ms |
3128 KB |
Output is correct |
5 |
Correct |
153 ms |
3132 KB |
Output is correct |
6 |
Correct |
91 ms |
3124 KB |
Output is correct |
7 |
Correct |
14 ms |
3028 KB |
Output is correct |
8 |
Correct |
11 ms |
3148 KB |
Output is correct |
9 |
Correct |
113 ms |
3132 KB |
Output is correct |
10 |
Correct |
99 ms |
3132 KB |
Output is correct |
11 |
Correct |
14 ms |
3148 KB |
Output is correct |
12 |
Correct |
133 ms |
3028 KB |
Output is correct |
13 |
Correct |
56 ms |
3132 KB |
Output is correct |
14 |
Correct |
125 ms |
3132 KB |
Output is correct |
15 |
Correct |
127 ms |
3028 KB |
Output is correct |
16 |
Correct |
80 ms |
3128 KB |
Output is correct |
17 |
Correct |
12 ms |
3144 KB |
Output is correct |
18 |
Correct |
11 ms |
3156 KB |
Output is correct |
19 |
Correct |
55 ms |
3028 KB |
Output is correct |
20 |
Correct |
90 ms |
3132 KB |
Output is correct |
21 |
Correct |
6 ms |
3028 KB |
Output is correct |
22 |
Correct |
8 ms |
3144 KB |
Output is correct |
23 |
Correct |
184 ms |
3132 KB |
Output is correct |
24 |
Correct |
95 ms |
3132 KB |
Output is correct |
25 |
Correct |
181 ms |
3124 KB |
Output is correct |
26 |
Correct |
210 ms |
3124 KB |
Output is correct |
27 |
Correct |
186 ms |
3128 KB |
Output is correct |
28 |
Correct |
196 ms |
3132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3028 KB |
Output is correct |
2 |
Correct |
5 ms |
3028 KB |
Output is correct |
3 |
Correct |
3 ms |
3028 KB |
Output is correct |
4 |
Correct |
12 ms |
3028 KB |
Output is correct |
5 |
Runtime error |
4 ms |
6100 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
3028 KB |
Output is correct |
2 |
Correct |
159 ms |
3132 KB |
Output is correct |
3 |
Correct |
56 ms |
3148 KB |
Output is correct |
4 |
Correct |
138 ms |
3128 KB |
Output is correct |
5 |
Correct |
153 ms |
3132 KB |
Output is correct |
6 |
Correct |
91 ms |
3124 KB |
Output is correct |
7 |
Correct |
14 ms |
3028 KB |
Output is correct |
8 |
Correct |
11 ms |
3148 KB |
Output is correct |
9 |
Correct |
113 ms |
3132 KB |
Output is correct |
10 |
Correct |
99 ms |
3132 KB |
Output is correct |
11 |
Correct |
14 ms |
3148 KB |
Output is correct |
12 |
Correct |
133 ms |
3028 KB |
Output is correct |
13 |
Correct |
56 ms |
3132 KB |
Output is correct |
14 |
Correct |
125 ms |
3132 KB |
Output is correct |
15 |
Correct |
127 ms |
3028 KB |
Output is correct |
16 |
Correct |
80 ms |
3128 KB |
Output is correct |
17 |
Correct |
12 ms |
3144 KB |
Output is correct |
18 |
Correct |
11 ms |
3156 KB |
Output is correct |
19 |
Correct |
55 ms |
3028 KB |
Output is correct |
20 |
Correct |
90 ms |
3132 KB |
Output is correct |
21 |
Correct |
6 ms |
3028 KB |
Output is correct |
22 |
Correct |
8 ms |
3144 KB |
Output is correct |
23 |
Correct |
184 ms |
3132 KB |
Output is correct |
24 |
Correct |
95 ms |
3132 KB |
Output is correct |
25 |
Correct |
181 ms |
3124 KB |
Output is correct |
26 |
Correct |
210 ms |
3124 KB |
Output is correct |
27 |
Correct |
186 ms |
3128 KB |
Output is correct |
28 |
Correct |
196 ms |
3132 KB |
Output is correct |
29 |
Correct |
11 ms |
3028 KB |
Output is correct |
30 |
Correct |
136 ms |
3132 KB |
Output is correct |
31 |
Correct |
50 ms |
3148 KB |
Output is correct |
32 |
Correct |
120 ms |
3132 KB |
Output is correct |
33 |
Correct |
127 ms |
3028 KB |
Output is correct |
34 |
Correct |
88 ms |
3128 KB |
Output is correct |
35 |
Correct |
12 ms |
3144 KB |
Output is correct |
36 |
Correct |
11 ms |
3144 KB |
Output is correct |
37 |
Correct |
54 ms |
3128 KB |
Output is correct |
38 |
Correct |
92 ms |
3136 KB |
Output is correct |
39 |
Correct |
6 ms |
3028 KB |
Output is correct |
40 |
Correct |
8 ms |
3028 KB |
Output is correct |
41 |
Correct |
184 ms |
3028 KB |
Output is correct |
42 |
Correct |
94 ms |
3028 KB |
Output is correct |
43 |
Correct |
186 ms |
3128 KB |
Output is correct |
44 |
Correct |
212 ms |
3124 KB |
Output is correct |
45 |
Correct |
167 ms |
3128 KB |
Output is correct |
46 |
Correct |
186 ms |
3132 KB |
Output is correct |
47 |
Correct |
8 ms |
3028 KB |
Output is correct |
48 |
Correct |
9 ms |
3112 KB |
Output is correct |
49 |
Correct |
364 ms |
3128 KB |
Output is correct |
50 |
Correct |
162 ms |
3124 KB |
Output is correct |
51 |
Correct |
382 ms |
3140 KB |
Output is correct |
52 |
Correct |
408 ms |
3132 KB |
Output is correct |
53 |
Correct |
335 ms |
3124 KB |
Output is correct |
54 |
Correct |
315 ms |
3028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3028 KB |
Output is correct |
2 |
Correct |
5 ms |
3028 KB |
Output is correct |
3 |
Correct |
3 ms |
3028 KB |
Output is correct |
4 |
Correct |
12 ms |
3028 KB |
Output is correct |
5 |
Runtime error |
4 ms |
6100 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
3028 KB |
Output is correct |
2 |
Correct |
159 ms |
3132 KB |
Output is correct |
3 |
Correct |
56 ms |
3148 KB |
Output is correct |
4 |
Correct |
138 ms |
3128 KB |
Output is correct |
5 |
Correct |
153 ms |
3132 KB |
Output is correct |
6 |
Correct |
91 ms |
3124 KB |
Output is correct |
7 |
Correct |
14 ms |
3028 KB |
Output is correct |
8 |
Correct |
11 ms |
3148 KB |
Output is correct |
9 |
Correct |
113 ms |
3132 KB |
Output is correct |
10 |
Correct |
99 ms |
3132 KB |
Output is correct |
11 |
Correct |
14 ms |
3148 KB |
Output is correct |
12 |
Correct |
133 ms |
3028 KB |
Output is correct |
13 |
Correct |
56 ms |
3132 KB |
Output is correct |
14 |
Correct |
125 ms |
3132 KB |
Output is correct |
15 |
Correct |
127 ms |
3028 KB |
Output is correct |
16 |
Correct |
80 ms |
3128 KB |
Output is correct |
17 |
Correct |
12 ms |
3144 KB |
Output is correct |
18 |
Correct |
11 ms |
3156 KB |
Output is correct |
19 |
Correct |
55 ms |
3028 KB |
Output is correct |
20 |
Correct |
90 ms |
3132 KB |
Output is correct |
21 |
Correct |
6 ms |
3028 KB |
Output is correct |
22 |
Correct |
8 ms |
3144 KB |
Output is correct |
23 |
Correct |
184 ms |
3132 KB |
Output is correct |
24 |
Correct |
95 ms |
3132 KB |
Output is correct |
25 |
Correct |
181 ms |
3124 KB |
Output is correct |
26 |
Correct |
210 ms |
3124 KB |
Output is correct |
27 |
Correct |
186 ms |
3128 KB |
Output is correct |
28 |
Correct |
196 ms |
3132 KB |
Output is correct |
29 |
Correct |
11 ms |
3028 KB |
Output is correct |
30 |
Correct |
136 ms |
3132 KB |
Output is correct |
31 |
Correct |
50 ms |
3148 KB |
Output is correct |
32 |
Correct |
120 ms |
3132 KB |
Output is correct |
33 |
Correct |
127 ms |
3028 KB |
Output is correct |
34 |
Correct |
88 ms |
3128 KB |
Output is correct |
35 |
Correct |
12 ms |
3144 KB |
Output is correct |
36 |
Correct |
11 ms |
3144 KB |
Output is correct |
37 |
Correct |
54 ms |
3128 KB |
Output is correct |
38 |
Correct |
92 ms |
3136 KB |
Output is correct |
39 |
Correct |
6 ms |
3028 KB |
Output is correct |
40 |
Correct |
8 ms |
3028 KB |
Output is correct |
41 |
Correct |
184 ms |
3028 KB |
Output is correct |
42 |
Correct |
94 ms |
3028 KB |
Output is correct |
43 |
Correct |
186 ms |
3128 KB |
Output is correct |
44 |
Correct |
212 ms |
3124 KB |
Output is correct |
45 |
Correct |
167 ms |
3128 KB |
Output is correct |
46 |
Correct |
186 ms |
3132 KB |
Output is correct |
47 |
Correct |
8 ms |
3028 KB |
Output is correct |
48 |
Correct |
9 ms |
3112 KB |
Output is correct |
49 |
Correct |
364 ms |
3128 KB |
Output is correct |
50 |
Correct |
162 ms |
3124 KB |
Output is correct |
51 |
Correct |
382 ms |
3140 KB |
Output is correct |
52 |
Correct |
408 ms |
3132 KB |
Output is correct |
53 |
Correct |
335 ms |
3124 KB |
Output is correct |
54 |
Correct |
315 ms |
3028 KB |
Output is correct |
55 |
Correct |
11 ms |
3144 KB |
Output is correct |
56 |
Correct |
135 ms |
3124 KB |
Output is correct |
57 |
Correct |
54 ms |
3028 KB |
Output is correct |
58 |
Correct |
122 ms |
3028 KB |
Output is correct |
59 |
Correct |
121 ms |
3028 KB |
Output is correct |
60 |
Correct |
79 ms |
3028 KB |
Output is correct |
61 |
Correct |
12 ms |
3028 KB |
Output is correct |
62 |
Correct |
10 ms |
3028 KB |
Output is correct |
63 |
Correct |
57 ms |
3132 KB |
Output is correct |
64 |
Correct |
87 ms |
3028 KB |
Output is correct |
65 |
Correct |
6 ms |
3044 KB |
Output is correct |
66 |
Correct |
8 ms |
3148 KB |
Output is correct |
67 |
Correct |
173 ms |
3128 KB |
Output is correct |
68 |
Correct |
99 ms |
3124 KB |
Output is correct |
69 |
Correct |
177 ms |
3140 KB |
Output is correct |
70 |
Correct |
206 ms |
3124 KB |
Output is correct |
71 |
Correct |
163 ms |
3124 KB |
Output is correct |
72 |
Correct |
189 ms |
3124 KB |
Output is correct |
73 |
Correct |
7 ms |
3028 KB |
Output is correct |
74 |
Correct |
9 ms |
3028 KB |
Output is correct |
75 |
Correct |
360 ms |
3028 KB |
Output is correct |
76 |
Correct |
163 ms |
3124 KB |
Output is correct |
77 |
Correct |
385 ms |
3124 KB |
Output is correct |
78 |
Correct |
407 ms |
3128 KB |
Output is correct |
79 |
Correct |
330 ms |
3028 KB |
Output is correct |
80 |
Correct |
335 ms |
3128 KB |
Output is correct |
81 |
Correct |
1229 ms |
3276 KB |
Output is correct |
82 |
Correct |
538 ms |
3136 KB |
Output is correct |
83 |
Correct |
1170 ms |
3256 KB |
Output is correct |
84 |
Correct |
1233 ms |
3276 KB |
Output is correct |
85 |
Correct |
10 ms |
3144 KB |
Output is correct |
86 |
Correct |
11 ms |
3028 KB |
Output is correct |
87 |
Correct |
1080 ms |
3132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3028 KB |
Output is correct |
2 |
Correct |
5 ms |
3028 KB |
Output is correct |
3 |
Correct |
3 ms |
3028 KB |
Output is correct |
4 |
Correct |
12 ms |
3028 KB |
Output is correct |
5 |
Runtime error |
4 ms |
6100 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |