#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
int amt[606];
int 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;
}
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) {
assert(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) {
MX(bst[j-d*i], bst[j]-d);
}
}else{
FOR(j, d*i, rng*2+1) {
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
3028 KB |
Output is correct |
2 |
Correct |
3 ms |
3028 KB |
Output is correct |
3 |
Correct |
3 ms |
3156 KB |
Output is correct |
4 |
Correct |
10 ms |
3148 KB |
Output is correct |
5 |
Runtime error |
4 ms |
6120 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
3028 KB |
Output is correct |
2 |
Correct |
3 ms |
3028 KB |
Output is correct |
3 |
Correct |
3 ms |
3156 KB |
Output is correct |
4 |
Correct |
10 ms |
3148 KB |
Output is correct |
5 |
Runtime error |
4 ms |
6120 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
3148 KB |
Output is correct |
2 |
Correct |
133 ms |
3128 KB |
Output is correct |
3 |
Correct |
45 ms |
3140 KB |
Output is correct |
4 |
Correct |
117 ms |
3128 KB |
Output is correct |
5 |
Correct |
116 ms |
3128 KB |
Output is correct |
6 |
Correct |
93 ms |
3128 KB |
Output is correct |
7 |
Correct |
12 ms |
3028 KB |
Output is correct |
8 |
Correct |
11 ms |
3144 KB |
Output is correct |
9 |
Correct |
54 ms |
3124 KB |
Output is correct |
10 |
Correct |
81 ms |
3140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
3148 KB |
Output is correct |
2 |
Correct |
133 ms |
3128 KB |
Output is correct |
3 |
Correct |
45 ms |
3140 KB |
Output is correct |
4 |
Correct |
117 ms |
3128 KB |
Output is correct |
5 |
Correct |
116 ms |
3128 KB |
Output is correct |
6 |
Correct |
93 ms |
3128 KB |
Output is correct |
7 |
Correct |
12 ms |
3028 KB |
Output is correct |
8 |
Correct |
11 ms |
3144 KB |
Output is correct |
9 |
Correct |
54 ms |
3124 KB |
Output is correct |
10 |
Correct |
81 ms |
3140 KB |
Output is correct |
11 |
Correct |
4 ms |
3028 KB |
Output is correct |
12 |
Correct |
3 ms |
3028 KB |
Output is correct |
13 |
Correct |
3 ms |
3032 KB |
Output is correct |
14 |
Correct |
11 ms |
3144 KB |
Output is correct |
15 |
Correct |
119 ms |
3120 KB |
Output is correct |
16 |
Correct |
41 ms |
3028 KB |
Output is correct |
17 |
Correct |
122 ms |
3128 KB |
Output is correct |
18 |
Correct |
122 ms |
3132 KB |
Output is correct |
19 |
Correct |
80 ms |
3028 KB |
Output is correct |
20 |
Correct |
13 ms |
3028 KB |
Output is correct |
21 |
Correct |
12 ms |
3028 KB |
Output is correct |
22 |
Correct |
61 ms |
3124 KB |
Output is correct |
23 |
Correct |
81 ms |
3128 KB |
Output is correct |
24 |
Correct |
243 ms |
3128 KB |
Output is correct |
25 |
Correct |
78 ms |
3132 KB |
Output is correct |
26 |
Correct |
217 ms |
3128 KB |
Output is correct |
27 |
Correct |
156 ms |
3128 KB |
Output is correct |
28 |
Correct |
247 ms |
3128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
3148 KB |
Output is correct |
2 |
Correct |
133 ms |
3128 KB |
Output is correct |
3 |
Correct |
45 ms |
3140 KB |
Output is correct |
4 |
Correct |
117 ms |
3128 KB |
Output is correct |
5 |
Correct |
116 ms |
3128 KB |
Output is correct |
6 |
Correct |
93 ms |
3128 KB |
Output is correct |
7 |
Correct |
12 ms |
3028 KB |
Output is correct |
8 |
Correct |
11 ms |
3144 KB |
Output is correct |
9 |
Correct |
54 ms |
3124 KB |
Output is correct |
10 |
Correct |
81 ms |
3140 KB |
Output is correct |
11 |
Correct |
11 ms |
3144 KB |
Output is correct |
12 |
Correct |
118 ms |
3128 KB |
Output is correct |
13 |
Correct |
40 ms |
3148 KB |
Output is correct |
14 |
Correct |
111 ms |
3124 KB |
Output is correct |
15 |
Correct |
109 ms |
3124 KB |
Output is correct |
16 |
Correct |
84 ms |
3132 KB |
Output is correct |
17 |
Correct |
14 ms |
3148 KB |
Output is correct |
18 |
Correct |
11 ms |
3028 KB |
Output is correct |
19 |
Correct |
52 ms |
3028 KB |
Output is correct |
20 |
Correct |
77 ms |
3140 KB |
Output is correct |
21 |
Correct |
6 ms |
3028 KB |
Output is correct |
22 |
Correct |
9 ms |
3156 KB |
Output is correct |
23 |
Correct |
181 ms |
3028 KB |
Output is correct |
24 |
Correct |
111 ms |
3144 KB |
Output is correct |
25 |
Correct |
151 ms |
3128 KB |
Output is correct |
26 |
Correct |
199 ms |
3124 KB |
Output is correct |
27 |
Correct |
185 ms |
3132 KB |
Output is correct |
28 |
Correct |
160 ms |
3144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
3028 KB |
Output is correct |
2 |
Correct |
3 ms |
3028 KB |
Output is correct |
3 |
Correct |
3 ms |
3156 KB |
Output is correct |
4 |
Correct |
10 ms |
3148 KB |
Output is correct |
5 |
Runtime error |
4 ms |
6120 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
3148 KB |
Output is correct |
2 |
Correct |
133 ms |
3128 KB |
Output is correct |
3 |
Correct |
45 ms |
3140 KB |
Output is correct |
4 |
Correct |
117 ms |
3128 KB |
Output is correct |
5 |
Correct |
116 ms |
3128 KB |
Output is correct |
6 |
Correct |
93 ms |
3128 KB |
Output is correct |
7 |
Correct |
12 ms |
3028 KB |
Output is correct |
8 |
Correct |
11 ms |
3144 KB |
Output is correct |
9 |
Correct |
54 ms |
3124 KB |
Output is correct |
10 |
Correct |
81 ms |
3140 KB |
Output is correct |
11 |
Correct |
11 ms |
3144 KB |
Output is correct |
12 |
Correct |
118 ms |
3128 KB |
Output is correct |
13 |
Correct |
40 ms |
3148 KB |
Output is correct |
14 |
Correct |
111 ms |
3124 KB |
Output is correct |
15 |
Correct |
109 ms |
3124 KB |
Output is correct |
16 |
Correct |
84 ms |
3132 KB |
Output is correct |
17 |
Correct |
14 ms |
3148 KB |
Output is correct |
18 |
Correct |
11 ms |
3028 KB |
Output is correct |
19 |
Correct |
52 ms |
3028 KB |
Output is correct |
20 |
Correct |
77 ms |
3140 KB |
Output is correct |
21 |
Correct |
6 ms |
3028 KB |
Output is correct |
22 |
Correct |
9 ms |
3156 KB |
Output is correct |
23 |
Correct |
181 ms |
3028 KB |
Output is correct |
24 |
Correct |
111 ms |
3144 KB |
Output is correct |
25 |
Correct |
151 ms |
3128 KB |
Output is correct |
26 |
Correct |
199 ms |
3124 KB |
Output is correct |
27 |
Correct |
185 ms |
3132 KB |
Output is correct |
28 |
Correct |
160 ms |
3144 KB |
Output is correct |
29 |
Correct |
10 ms |
3028 KB |
Output is correct |
30 |
Correct |
118 ms |
3132 KB |
Output is correct |
31 |
Correct |
46 ms |
3148 KB |
Output is correct |
32 |
Correct |
124 ms |
3028 KB |
Output is correct |
33 |
Correct |
125 ms |
3128 KB |
Output is correct |
34 |
Correct |
76 ms |
3124 KB |
Output is correct |
35 |
Correct |
12 ms |
3148 KB |
Output is correct |
36 |
Correct |
13 ms |
3144 KB |
Output is correct |
37 |
Correct |
53 ms |
3128 KB |
Output is correct |
38 |
Correct |
89 ms |
3128 KB |
Output is correct |
39 |
Correct |
6 ms |
3152 KB |
Output is correct |
40 |
Correct |
10 ms |
3144 KB |
Output is correct |
41 |
Correct |
159 ms |
3028 KB |
Output is correct |
42 |
Correct |
81 ms |
3148 KB |
Output is correct |
43 |
Correct |
158 ms |
3124 KB |
Output is correct |
44 |
Correct |
214 ms |
3028 KB |
Output is correct |
45 |
Correct |
181 ms |
3128 KB |
Output is correct |
46 |
Correct |
167 ms |
3140 KB |
Output is correct |
47 |
Correct |
7 ms |
3028 KB |
Output is correct |
48 |
Correct |
11 ms |
3028 KB |
Output is correct |
49 |
Correct |
345 ms |
3140 KB |
Output is correct |
50 |
Correct |
138 ms |
3128 KB |
Output is correct |
51 |
Correct |
374 ms |
3132 KB |
Output is correct |
52 |
Correct |
375 ms |
3124 KB |
Output is correct |
53 |
Correct |
382 ms |
3124 KB |
Output is correct |
54 |
Correct |
282 ms |
3196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
3028 KB |
Output is correct |
2 |
Correct |
3 ms |
3028 KB |
Output is correct |
3 |
Correct |
3 ms |
3156 KB |
Output is correct |
4 |
Correct |
10 ms |
3148 KB |
Output is correct |
5 |
Runtime error |
4 ms |
6120 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
3148 KB |
Output is correct |
2 |
Correct |
133 ms |
3128 KB |
Output is correct |
3 |
Correct |
45 ms |
3140 KB |
Output is correct |
4 |
Correct |
117 ms |
3128 KB |
Output is correct |
5 |
Correct |
116 ms |
3128 KB |
Output is correct |
6 |
Correct |
93 ms |
3128 KB |
Output is correct |
7 |
Correct |
12 ms |
3028 KB |
Output is correct |
8 |
Correct |
11 ms |
3144 KB |
Output is correct |
9 |
Correct |
54 ms |
3124 KB |
Output is correct |
10 |
Correct |
81 ms |
3140 KB |
Output is correct |
11 |
Correct |
11 ms |
3144 KB |
Output is correct |
12 |
Correct |
118 ms |
3128 KB |
Output is correct |
13 |
Correct |
40 ms |
3148 KB |
Output is correct |
14 |
Correct |
111 ms |
3124 KB |
Output is correct |
15 |
Correct |
109 ms |
3124 KB |
Output is correct |
16 |
Correct |
84 ms |
3132 KB |
Output is correct |
17 |
Correct |
14 ms |
3148 KB |
Output is correct |
18 |
Correct |
11 ms |
3028 KB |
Output is correct |
19 |
Correct |
52 ms |
3028 KB |
Output is correct |
20 |
Correct |
77 ms |
3140 KB |
Output is correct |
21 |
Correct |
6 ms |
3028 KB |
Output is correct |
22 |
Correct |
9 ms |
3156 KB |
Output is correct |
23 |
Correct |
181 ms |
3028 KB |
Output is correct |
24 |
Correct |
111 ms |
3144 KB |
Output is correct |
25 |
Correct |
151 ms |
3128 KB |
Output is correct |
26 |
Correct |
199 ms |
3124 KB |
Output is correct |
27 |
Correct |
185 ms |
3132 KB |
Output is correct |
28 |
Correct |
160 ms |
3144 KB |
Output is correct |
29 |
Correct |
10 ms |
3028 KB |
Output is correct |
30 |
Correct |
118 ms |
3132 KB |
Output is correct |
31 |
Correct |
46 ms |
3148 KB |
Output is correct |
32 |
Correct |
124 ms |
3028 KB |
Output is correct |
33 |
Correct |
125 ms |
3128 KB |
Output is correct |
34 |
Correct |
76 ms |
3124 KB |
Output is correct |
35 |
Correct |
12 ms |
3148 KB |
Output is correct |
36 |
Correct |
13 ms |
3144 KB |
Output is correct |
37 |
Correct |
53 ms |
3128 KB |
Output is correct |
38 |
Correct |
89 ms |
3128 KB |
Output is correct |
39 |
Correct |
6 ms |
3152 KB |
Output is correct |
40 |
Correct |
10 ms |
3144 KB |
Output is correct |
41 |
Correct |
159 ms |
3028 KB |
Output is correct |
42 |
Correct |
81 ms |
3148 KB |
Output is correct |
43 |
Correct |
158 ms |
3124 KB |
Output is correct |
44 |
Correct |
214 ms |
3028 KB |
Output is correct |
45 |
Correct |
181 ms |
3128 KB |
Output is correct |
46 |
Correct |
167 ms |
3140 KB |
Output is correct |
47 |
Correct |
7 ms |
3028 KB |
Output is correct |
48 |
Correct |
11 ms |
3028 KB |
Output is correct |
49 |
Correct |
345 ms |
3140 KB |
Output is correct |
50 |
Correct |
138 ms |
3128 KB |
Output is correct |
51 |
Correct |
374 ms |
3132 KB |
Output is correct |
52 |
Correct |
375 ms |
3124 KB |
Output is correct |
53 |
Correct |
382 ms |
3124 KB |
Output is correct |
54 |
Correct |
282 ms |
3196 KB |
Output is correct |
55 |
Correct |
14 ms |
3144 KB |
Output is correct |
56 |
Correct |
124 ms |
3132 KB |
Output is correct |
57 |
Correct |
42 ms |
3148 KB |
Output is correct |
58 |
Correct |
113 ms |
3124 KB |
Output is correct |
59 |
Correct |
116 ms |
3128 KB |
Output is correct |
60 |
Correct |
86 ms |
3128 KB |
Output is correct |
61 |
Correct |
14 ms |
3028 KB |
Output is correct |
62 |
Correct |
11 ms |
3028 KB |
Output is correct |
63 |
Correct |
55 ms |
3140 KB |
Output is correct |
64 |
Correct |
85 ms |
3120 KB |
Output is correct |
65 |
Correct |
6 ms |
3028 KB |
Output is correct |
66 |
Correct |
8 ms |
3028 KB |
Output is correct |
67 |
Correct |
168 ms |
3044 KB |
Output is correct |
68 |
Correct |
102 ms |
3028 KB |
Output is correct |
69 |
Correct |
166 ms |
3132 KB |
Output is correct |
70 |
Correct |
210 ms |
3124 KB |
Output is correct |
71 |
Correct |
170 ms |
3028 KB |
Output is correct |
72 |
Correct |
164 ms |
3136 KB |
Output is correct |
73 |
Correct |
8 ms |
3028 KB |
Output is correct |
74 |
Correct |
13 ms |
3148 KB |
Output is correct |
75 |
Correct |
352 ms |
3128 KB |
Output is correct |
76 |
Correct |
146 ms |
3028 KB |
Output is correct |
77 |
Correct |
419 ms |
3128 KB |
Output is correct |
78 |
Correct |
378 ms |
3124 KB |
Output is correct |
79 |
Correct |
368 ms |
3128 KB |
Output is correct |
80 |
Correct |
281 ms |
3128 KB |
Output is correct |
81 |
Correct |
1122 ms |
3128 KB |
Output is correct |
82 |
Correct |
503 ms |
3132 KB |
Output is correct |
83 |
Correct |
1107 ms |
3132 KB |
Output is correct |
84 |
Correct |
1246 ms |
3152 KB |
Output is correct |
85 |
Correct |
11 ms |
3028 KB |
Output is correct |
86 |
Correct |
12 ms |
3148 KB |
Output is correct |
87 |
Correct |
1055 ms |
3132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
3028 KB |
Output is correct |
2 |
Correct |
3 ms |
3028 KB |
Output is correct |
3 |
Correct |
3 ms |
3156 KB |
Output is correct |
4 |
Correct |
10 ms |
3148 KB |
Output is correct |
5 |
Runtime error |
4 ms |
6120 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |