#include<bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e18;
const int MAXV = 300;
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Incorrect |
2 ms |
860 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Incorrect |
2 ms |
860 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Incorrect |
2 ms |
860 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Incorrect |
2 ms |
860 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Incorrect |
2 ms |
860 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |