#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
ll mod=1000000007;
int inf=1000000007;
ll infl=1000000000000000007;
const int M=207;
ll a[2*M];
ll b[2*M];
ll DP[M*M*4];
void gg()
{
cout<<"impossible";
exit(0);
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int m;
ll l,sum=0,ans=0,act=0;
cin>>m>>l;
for(ll i=-m;i<=m;i++)
{
cin>>a[i+m];
sum+=a[i+m]*i;
}
ans+=a[m];
a[m]=0;
if(sum>=l)
{
for(ll i=-m;i<=m;i++)
{
ll x;
if(i<=0) x=a[i+m];
else x=min(a[i+m],(l-act)/i);
b[-i+m]+=x;
a[i+m]-=x;
ans+=x;
act+=i*x;
}
}
else
{
for(ll i=m;i>=-m;i--)
{
ll x;
if(i>=0) x=a[i+m];
else x=min(a[i+m],(l-act)/i);
b[-i+m]+=x;
a[i+m]-=x;
ans+=x;
act+=x*i;
}
}
for(int i=-4*m*m;i<=4*m*m;i++) DP[i+4*m*m]=-infl;
DP[4*m*m]=0;
for(int i=-m;i<=m;i++)
{
for(int j=-4*m*m;j<=4*m*m;j++)
{
for(int l=1;l<=min((ll)2*m+1,a[i+m]+b[i+m]);l++)
{
int k=j+l*i;
if(k<-4*m*m||k>4*m*m) continue;
ll x=min(a[i+m],(ll)l)-max(0LL,l-a[i+m]);
DP[k+4*m*m]=max(DP[k+4*m*m],DP[j+4*m*m]+x);
}
}
}
l-=act;
if(l<-4*m*m||l>4*m*m) gg();
else
{
if(ans+DP[l+4*m*m]<0) gg();
cout<<ans+(ll)DP[l+4*m*m];
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
87 ms |
468 KB |
Output is correct |
6 |
Correct |
98 ms |
468 KB |
Output is correct |
7 |
Correct |
42 ms |
468 KB |
Output is correct |
8 |
Correct |
93 ms |
468 KB |
Output is correct |
9 |
Correct |
157 ms |
480 KB |
Output is correct |
10 |
Correct |
5 ms |
468 KB |
Output is correct |
11 |
Correct |
5 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
87 ms |
468 KB |
Output is correct |
6 |
Correct |
98 ms |
468 KB |
Output is correct |
7 |
Correct |
42 ms |
468 KB |
Output is correct |
8 |
Correct |
93 ms |
468 KB |
Output is correct |
9 |
Correct |
157 ms |
480 KB |
Output is correct |
10 |
Correct |
5 ms |
468 KB |
Output is correct |
11 |
Correct |
5 ms |
468 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
95 ms |
484 KB |
Output is correct |
17 |
Correct |
97 ms |
468 KB |
Output is correct |
18 |
Correct |
37 ms |
468 KB |
Output is correct |
19 |
Correct |
88 ms |
468 KB |
Output is correct |
20 |
Correct |
168 ms |
468 KB |
Output is correct |
21 |
Correct |
6 ms |
468 KB |
Output is correct |
22 |
Correct |
8 ms |
468 KB |
Output is correct |
23 |
Correct |
1366 ms |
940 KB |
Output is correct |
24 |
Correct |
1431 ms |
936 KB |
Output is correct |
25 |
Incorrect |
497 ms |
972 KB |
Output isn't correct |
26 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
13 ms |
340 KB |
Output is correct |
3 |
Incorrect |
4 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
13 ms |
340 KB |
Output is correct |
3 |
Incorrect |
4 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
13 ms |
340 KB |
Output is correct |
3 |
Incorrect |
4 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
87 ms |
468 KB |
Output is correct |
6 |
Correct |
98 ms |
468 KB |
Output is correct |
7 |
Correct |
42 ms |
468 KB |
Output is correct |
8 |
Correct |
93 ms |
468 KB |
Output is correct |
9 |
Correct |
157 ms |
480 KB |
Output is correct |
10 |
Correct |
5 ms |
468 KB |
Output is correct |
11 |
Correct |
5 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
13 ms |
340 KB |
Output is correct |
14 |
Incorrect |
4 ms |
340 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
13 ms |
340 KB |
Output is correct |
3 |
Incorrect |
4 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
87 ms |
468 KB |
Output is correct |
6 |
Correct |
98 ms |
468 KB |
Output is correct |
7 |
Correct |
42 ms |
468 KB |
Output is correct |
8 |
Correct |
93 ms |
468 KB |
Output is correct |
9 |
Correct |
157 ms |
480 KB |
Output is correct |
10 |
Correct |
5 ms |
468 KB |
Output is correct |
11 |
Correct |
5 ms |
468 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
95 ms |
484 KB |
Output is correct |
17 |
Correct |
97 ms |
468 KB |
Output is correct |
18 |
Correct |
37 ms |
468 KB |
Output is correct |
19 |
Correct |
88 ms |
468 KB |
Output is correct |
20 |
Correct |
168 ms |
468 KB |
Output is correct |
21 |
Correct |
6 ms |
468 KB |
Output is correct |
22 |
Correct |
8 ms |
468 KB |
Output is correct |
23 |
Correct |
1366 ms |
940 KB |
Output is correct |
24 |
Correct |
1431 ms |
936 KB |
Output is correct |
25 |
Incorrect |
497 ms |
972 KB |
Output isn't correct |
26 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
13 ms |
340 KB |
Output is correct |
3 |
Incorrect |
4 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
87 ms |
468 KB |
Output is correct |
6 |
Correct |
98 ms |
468 KB |
Output is correct |
7 |
Correct |
42 ms |
468 KB |
Output is correct |
8 |
Correct |
93 ms |
468 KB |
Output is correct |
9 |
Correct |
157 ms |
480 KB |
Output is correct |
10 |
Correct |
5 ms |
468 KB |
Output is correct |
11 |
Correct |
5 ms |
468 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
95 ms |
484 KB |
Output is correct |
17 |
Correct |
97 ms |
468 KB |
Output is correct |
18 |
Correct |
37 ms |
468 KB |
Output is correct |
19 |
Correct |
88 ms |
468 KB |
Output is correct |
20 |
Correct |
168 ms |
468 KB |
Output is correct |
21 |
Correct |
6 ms |
468 KB |
Output is correct |
22 |
Correct |
8 ms |
468 KB |
Output is correct |
23 |
Correct |
1366 ms |
940 KB |
Output is correct |
24 |
Correct |
1431 ms |
936 KB |
Output is correct |
25 |
Incorrect |
497 ms |
972 KB |
Output isn't correct |
26 |
Halted |
0 ms |
0 KB |
- |