#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr first
#define sc second
const int mxn=305;
ll m,a[mxn*2],l,sum,ans,num;
vector<pair<ll,ll>>v;
ll dp[2][mxn*mxn*2];
void add(ll tedad,ll x,ll z){
tedad=(min(tedad,m*2));
for(ll i=1;i<=tedad;i*=2){
v.push_back({i*x,z*i});
tedad-=i;
}
if(tedad>0)
v.push_back({tedad*x,z*tedad});
}
void solve(){
for(ll i=m;i<2*m+1;i++){
ans+=a[i];
num+=a[i]*(i-m);
add(a[i],-(i-m),-1);
}
ll i=m-1;
for(;i>=0;i--){
if(num+a[i]*(i-m)>=l){
ans+=a[i];
num+=a[i]*(i-m);
add(a[i],-(i-m),-1);
continue;
}
ll x=num-l;
x=x/(i-m);
num+=a[i]*x;
ans+=x;
add(x,-(i-m),-1);
add(a[i]-x,i-m,1);
i--;
break;
}
for(;i>=0;i--){
add(a[i],(i-m),1);
}
}
void solve1(){
for(ll i=m;i>=0;i--){
ans+=a[i];
num+=a[i]*(i-m);
add(a[i],-(i-m),-1);
}
ll i=m+1;
for(;i<m*2+1;i++){
if(num+a[i]*(i-m)<=l){
ans+=a[i];
num+=a[i]*(i-m);
add(a[i],-(i-m),-1);
continue;
}
ll x=l-num;
x=x/(i-m);
x=min(x,a[i]);
num+=(i-m)*x;
ans+=x;
add(x,-(i-m),-1);
add(a[i]-x,i-m,1);
i++;
break;
}
for(;i<m*2+1;i++){
add(a[i],(i-m),1);
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>m>>l;
for(ll i=0;i<m*2+1;i++){
cin>>a[i];
sum+=(i-m)*a[i];
}
if(sum<=l)
solve();
else
solve1();
for(int i=0;i<=2*m*m;i++)dp[1][i]=-1e18;
dp[1][m*m]=0;
for(int i=0;i<v.size();i++){
ll x=v[i].fr,y=v[i].sc;
int z=i&1;
for(ll j=0;j<=2*m*m;j++){
if(j-x>=0 && j-x<=2*m*m && dp[z^1][j-x]!=-1e18)
dp[z][j]=max(dp[z^1][j],dp[z^1][j-x]+y);
else
dp[z][j]=dp[z^1][j];
}
//cout<<dp[z][928]<<" ";
}
int x=v.size()&1;
x^=1;
if(dp[x][l-num+m*m]==-1e18 || ans+dp[x][l-num+m*m]<0){
cout<<"impossible";
return 0;
}
cout<<ans+dp[x][l-num+m*m];
return 0;
}
Compilation message
vault.cpp: In function 'int main()':
vault.cpp:90:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
90 | for(int i=0;i<v.size();i++){
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
4 ms |
2396 KB |
Output is correct |
6 |
Incorrect |
5 ms |
2396 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
4 ms |
2396 KB |
Output is correct |
6 |
Incorrect |
5 ms |
2396 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2536 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
3 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2392 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2392 KB |
Output is correct |
26 |
Correct |
2 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2648 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2392 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
2 ms |
2392 KB |
Output is correct |
24 |
Correct |
1 ms |
2648 KB |
Output is correct |
25 |
Correct |
2 ms |
2396 KB |
Output is correct |
26 |
Correct |
2 ms |
2396 KB |
Output is correct |
27 |
Correct |
3 ms |
2532 KB |
Output is correct |
28 |
Correct |
2 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
4 ms |
2396 KB |
Output is correct |
6 |
Incorrect |
5 ms |
2396 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2648 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2392 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
2 ms |
2392 KB |
Output is correct |
24 |
Correct |
1 ms |
2648 KB |
Output is correct |
25 |
Correct |
2 ms |
2396 KB |
Output is correct |
26 |
Correct |
2 ms |
2396 KB |
Output is correct |
27 |
Correct |
3 ms |
2532 KB |
Output is correct |
28 |
Correct |
2 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2648 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
1 ms |
2396 KB |
Output is correct |
34 |
Correct |
1 ms |
2396 KB |
Output is correct |
35 |
Correct |
1 ms |
2648 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
2396 KB |
Output is correct |
38 |
Correct |
1 ms |
2396 KB |
Output is correct |
39 |
Correct |
1 ms |
2396 KB |
Output is correct |
40 |
Correct |
1 ms |
2396 KB |
Output is correct |
41 |
Correct |
2 ms |
2396 KB |
Output is correct |
42 |
Correct |
1 ms |
2396 KB |
Output is correct |
43 |
Correct |
2 ms |
2392 KB |
Output is correct |
44 |
Correct |
3 ms |
2648 KB |
Output is correct |
45 |
Correct |
2 ms |
2396 KB |
Output is correct |
46 |
Correct |
2 ms |
2396 KB |
Output is correct |
47 |
Correct |
2 ms |
2652 KB |
Output is correct |
48 |
Correct |
2 ms |
2652 KB |
Output is correct |
49 |
Correct |
16 ms |
2652 KB |
Output is correct |
50 |
Correct |
8 ms |
2692 KB |
Output is correct |
51 |
Correct |
18 ms |
2648 KB |
Output is correct |
52 |
Correct |
19 ms |
2648 KB |
Output is correct |
53 |
Correct |
16 ms |
2652 KB |
Output is correct |
54 |
Correct |
14 ms |
2652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
4 ms |
2396 KB |
Output is correct |
6 |
Incorrect |
5 ms |
2396 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2648 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2392 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
2 ms |
2392 KB |
Output is correct |
24 |
Correct |
1 ms |
2648 KB |
Output is correct |
25 |
Correct |
2 ms |
2396 KB |
Output is correct |
26 |
Correct |
2 ms |
2396 KB |
Output is correct |
27 |
Correct |
3 ms |
2532 KB |
Output is correct |
28 |
Correct |
2 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2648 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
1 ms |
2396 KB |
Output is correct |
34 |
Correct |
1 ms |
2396 KB |
Output is correct |
35 |
Correct |
1 ms |
2648 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
2396 KB |
Output is correct |
38 |
Correct |
1 ms |
2396 KB |
Output is correct |
39 |
Correct |
1 ms |
2396 KB |
Output is correct |
40 |
Correct |
1 ms |
2396 KB |
Output is correct |
41 |
Correct |
2 ms |
2396 KB |
Output is correct |
42 |
Correct |
1 ms |
2396 KB |
Output is correct |
43 |
Correct |
2 ms |
2392 KB |
Output is correct |
44 |
Correct |
3 ms |
2648 KB |
Output is correct |
45 |
Correct |
2 ms |
2396 KB |
Output is correct |
46 |
Correct |
2 ms |
2396 KB |
Output is correct |
47 |
Correct |
2 ms |
2652 KB |
Output is correct |
48 |
Correct |
2 ms |
2652 KB |
Output is correct |
49 |
Correct |
16 ms |
2652 KB |
Output is correct |
50 |
Correct |
8 ms |
2692 KB |
Output is correct |
51 |
Correct |
18 ms |
2648 KB |
Output is correct |
52 |
Correct |
19 ms |
2648 KB |
Output is correct |
53 |
Correct |
16 ms |
2652 KB |
Output is correct |
54 |
Correct |
14 ms |
2652 KB |
Output is correct |
55 |
Correct |
1 ms |
2392 KB |
Output is correct |
56 |
Correct |
1 ms |
2396 KB |
Output is correct |
57 |
Correct |
1 ms |
2396 KB |
Output is correct |
58 |
Correct |
1 ms |
2396 KB |
Output is correct |
59 |
Correct |
1 ms |
2396 KB |
Output is correct |
60 |
Correct |
1 ms |
2396 KB |
Output is correct |
61 |
Correct |
1 ms |
2396 KB |
Output is correct |
62 |
Correct |
1 ms |
2396 KB |
Output is correct |
63 |
Correct |
1 ms |
2396 KB |
Output is correct |
64 |
Correct |
1 ms |
2396 KB |
Output is correct |
65 |
Correct |
1 ms |
2392 KB |
Output is correct |
66 |
Correct |
1 ms |
2396 KB |
Output is correct |
67 |
Correct |
2 ms |
2396 KB |
Output is correct |
68 |
Correct |
1 ms |
2396 KB |
Output is correct |
69 |
Correct |
2 ms |
2396 KB |
Output is correct |
70 |
Correct |
3 ms |
2396 KB |
Output is correct |
71 |
Correct |
2 ms |
2396 KB |
Output is correct |
72 |
Correct |
2 ms |
2396 KB |
Output is correct |
73 |
Correct |
1 ms |
2652 KB |
Output is correct |
74 |
Correct |
1 ms |
2652 KB |
Output is correct |
75 |
Correct |
16 ms |
2696 KB |
Output is correct |
76 |
Correct |
7 ms |
2652 KB |
Output is correct |
77 |
Correct |
19 ms |
2700 KB |
Output is correct |
78 |
Correct |
20 ms |
2648 KB |
Output is correct |
79 |
Correct |
17 ms |
2652 KB |
Output is correct |
80 |
Correct |
14 ms |
2652 KB |
Output is correct |
81 |
Correct |
558 ms |
3420 KB |
Output is correct |
82 |
Correct |
243 ms |
3160 KB |
Output is correct |
83 |
Correct |
596 ms |
3416 KB |
Output is correct |
84 |
Correct |
641 ms |
3420 KB |
Output is correct |
85 |
Correct |
9 ms |
3160 KB |
Output is correct |
86 |
Correct |
10 ms |
3328 KB |
Output is correct |
87 |
Correct |
493 ms |
3428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
4 ms |
2396 KB |
Output is correct |
6 |
Incorrect |
5 ms |
2396 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |