#include<bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e18;
const int MAXV = 46000;
int m,L;
int a[700];
int dp[700][2*MAXV+5];
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>m>>L;
for(int i=-m*m;i<=m*m;i++)
dp[0][MAXV+i]=-INF;
dp[0][MAXV+0]=0;
for(int i=-m;i<=m;i++)
{
cin>>a[m+i+1];
for(int sum=-m*m;sum<=m*m;sum++)
{
dp[m+i+1][MAXV+sum] = dp[m+i][MAXV+sum];
for(int cnt=1;cnt<=a[m+i+1];cnt++)
{
if(abs(sum - cnt*i) > m*m)
break;
if(dp[m+i][MAXV+sum-cnt*i] > -INF) dp[m+i+1][MAXV+sum] = max(dp[m+i+1][MAXV+sum], dp[m+i][MAXV+sum-cnt*i] + cnt);
}
}
}
int rez=-INF;
if(abs(L)<=abs(m*m))
{
rez = dp[2*m+1][MAXV+L];
}
else
{
for(int d=1;d<=m;d++)
{
int r = L%d;
for(int cnt=0;r+cnt*d<=m*m;cnt++)
{
rez = max(rez, dp[2*m+1][MAXV+r+cnt*d] + L/d - cnt);
}
}
}
if(rez==-INF)
cout<<"impossible";
else
cout<<rez;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Incorrect |
5 ms |
1628 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Incorrect |
5 ms |
1628 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Incorrect |
5 ms |
1628 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Incorrect |
5 ms |
1628 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Incorrect |
5 ms |
1628 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |