#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=-MAXV;i<=MAXV;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=-MAXV;sum<=MAXV;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) > MAXV)
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(MAXV))
{
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<=MAXV;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 |
Correct |
4 ms |
4696 KB |
Output is correct |
2 |
Correct |
4 ms |
5980 KB |
Output is correct |
3 |
Correct |
3 ms |
3164 KB |
Output is correct |
4 |
Correct |
15 ms |
16220 KB |
Output is correct |
5 |
Incorrect |
306 ms |
73812 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4696 KB |
Output is correct |
2 |
Correct |
4 ms |
5980 KB |
Output is correct |
3 |
Correct |
3 ms |
3164 KB |
Output is correct |
4 |
Correct |
15 ms |
16220 KB |
Output is correct |
5 |
Incorrect |
306 ms |
73812 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
16216 KB |
Output is correct |
2 |
Execution timed out |
5074 ms |
28976 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
16216 KB |
Output is correct |
2 |
Execution timed out |
5074 ms |
28976 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
16216 KB |
Output is correct |
2 |
Execution timed out |
5074 ms |
28976 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4696 KB |
Output is correct |
2 |
Correct |
4 ms |
5980 KB |
Output is correct |
3 |
Correct |
3 ms |
3164 KB |
Output is correct |
4 |
Correct |
15 ms |
16220 KB |
Output is correct |
5 |
Incorrect |
306 ms |
73812 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
16216 KB |
Output is correct |
2 |
Execution timed out |
5074 ms |
28976 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4696 KB |
Output is correct |
2 |
Correct |
4 ms |
5980 KB |
Output is correct |
3 |
Correct |
3 ms |
3164 KB |
Output is correct |
4 |
Correct |
15 ms |
16220 KB |
Output is correct |
5 |
Incorrect |
306 ms |
73812 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
16216 KB |
Output is correct |
2 |
Execution timed out |
5074 ms |
28976 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4696 KB |
Output is correct |
2 |
Correct |
4 ms |
5980 KB |
Output is correct |
3 |
Correct |
3 ms |
3164 KB |
Output is correct |
4 |
Correct |
15 ms |
16220 KB |
Output is correct |
5 |
Incorrect |
306 ms |
73812 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |