#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*2];
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,X=0,Y=0;
cin>>m>>l;
for(ll i=-m;i<=m;i++)
{
cin>>a[i+m];
sum+=a[i+m]*i;
if(i<0) X+=a[i+m]*i;
else Y+=a[i+m]*i;
}
if(l<0&&l<X) gg();
if(l>0&&Y<l) gg();
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=-2*m*m;i<=2*m*m;i++) DP[i+2*m*m]=-infl;
DP[2*m*m]=0;
for(int i=-m;i<=m;i++)
{
for(int j=-2*m*m;j<=2*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<-2*m*m||k>2*m*m) continue;
ll x=min(a[i+m],(ll)l)-max(0LL,l-a[i+m]);
DP[k+2*m*m]=max(DP[k+2*m*m],DP[j+2*m*m]+x);
}
}
}
l-=act;
if(l<-2*m*m||l>2*m*m) gg();
else
{
if(ans+DP[l+2*m*m]<0) gg();
cout<<ans+(ll)DP[l+2*m*m];
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
46 ms |
340 KB |
Output is correct |
7 |
Correct |
22 ms |
340 KB |
Output is correct |
8 |
Correct |
48 ms |
340 KB |
Output is correct |
9 |
Correct |
79 ms |
340 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
4 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
46 ms |
340 KB |
Output is correct |
7 |
Correct |
22 ms |
340 KB |
Output is correct |
8 |
Correct |
48 ms |
340 KB |
Output is correct |
9 |
Correct |
79 ms |
340 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
4 ms |
340 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 |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
49 ms |
340 KB |
Output is correct |
18 |
Correct |
20 ms |
408 KB |
Output is correct |
19 |
Correct |
56 ms |
392 KB |
Output is correct |
20 |
Correct |
81 ms |
388 KB |
Output is correct |
21 |
Correct |
5 ms |
340 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
693 ms |
628 KB |
Output is correct |
25 |
Incorrect |
259 ms |
624 KB |
Output isn't correct |
26 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
7 ms |
364 KB |
Output is correct |
3 |
Incorrect |
3 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 |
7 ms |
364 KB |
Output is correct |
3 |
Incorrect |
3 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 |
7 ms |
364 KB |
Output is correct |
3 |
Incorrect |
3 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 |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
46 ms |
340 KB |
Output is correct |
7 |
Correct |
22 ms |
340 KB |
Output is correct |
8 |
Correct |
48 ms |
340 KB |
Output is correct |
9 |
Correct |
79 ms |
340 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
4 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
7 ms |
364 KB |
Output is correct |
14 |
Incorrect |
3 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 |
7 ms |
364 KB |
Output is correct |
3 |
Incorrect |
3 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 |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
46 ms |
340 KB |
Output is correct |
7 |
Correct |
22 ms |
340 KB |
Output is correct |
8 |
Correct |
48 ms |
340 KB |
Output is correct |
9 |
Correct |
79 ms |
340 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
4 ms |
340 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 |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
49 ms |
340 KB |
Output is correct |
18 |
Correct |
20 ms |
408 KB |
Output is correct |
19 |
Correct |
56 ms |
392 KB |
Output is correct |
20 |
Correct |
81 ms |
388 KB |
Output is correct |
21 |
Correct |
5 ms |
340 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
693 ms |
628 KB |
Output is correct |
25 |
Incorrect |
259 ms |
624 KB |
Output isn't correct |
26 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
7 ms |
364 KB |
Output is correct |
3 |
Incorrect |
3 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 |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
46 ms |
340 KB |
Output is correct |
7 |
Correct |
22 ms |
340 KB |
Output is correct |
8 |
Correct |
48 ms |
340 KB |
Output is correct |
9 |
Correct |
79 ms |
340 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
4 ms |
340 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 |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
49 ms |
340 KB |
Output is correct |
18 |
Correct |
20 ms |
408 KB |
Output is correct |
19 |
Correct |
56 ms |
392 KB |
Output is correct |
20 |
Correct |
81 ms |
388 KB |
Output is correct |
21 |
Correct |
5 ms |
340 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
693 ms |
628 KB |
Output is correct |
25 |
Incorrect |
259 ms |
624 KB |
Output isn't correct |
26 |
Halted |
0 ms |
0 KB |
- |