#include<bits/stdc++.h>
using namespace std;
long long int m,dp[300005];
long long int L;
int num[200005];
int val[200005];
int su = 0;
int main()
{
cin>>m>>L;
for(int i=1;i<=m*2+1;i++)
{
cin>>num[i];
val[i] = i-m-1;
su += num[i];
}
for(int i=1;i<=200000;i++)dp[i] = -1;
dp[100000] = num[m+1]; //遍移量為1000000
for (int i=m+2;i<=m*2+1;i++)
{
for(int j=1;j<=num[i];j++)
{
for(int k=200000;k>=1;k--)
{
if(k >= val[i])
{
if(dp[k-val[i]] == -1)continue;
if(dp[k] == -1)
{
dp[k] = dp[k-val[i]] + 1;
}
else dp[k] = max(dp[k-val[i]] + 1,dp[k]);
}
}
}
}
for (int i =1;i<=m;i++)
{
for(int j=1;j<=num[i];j++)
{
for(int k=1;k<=200000;k++)
{
if(k - val[i] <= 200000)
{
if(dp[k-val[i]] == -1)continue;
if(dp[k] == -1)dp[k] = dp[k-val[i]] + 1;
else dp[k] = max(dp[k-val[i]] + 1,dp[k]);
}
}
}
}
if(dp[L+100000] == -1 || L >= 100000 || L <= 0-100000)
{
cout<<"impossible"<<endl;
return 0;
}
else
{
cout<<dp[L+100000]<<endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3160 KB |
Output is correct |
2 |
Correct |
4 ms |
1884 KB |
Output is correct |
3 |
Correct |
2 ms |
1884 KB |
Output is correct |
4 |
Correct |
8 ms |
3164 KB |
Output is correct |
5 |
Runtime error |
420 ms |
3532 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3160 KB |
Output is correct |
2 |
Correct |
4 ms |
1884 KB |
Output is correct |
3 |
Correct |
2 ms |
1884 KB |
Output is correct |
4 |
Correct |
8 ms |
3164 KB |
Output is correct |
5 |
Runtime error |
420 ms |
3532 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1880 KB |
Output is correct |
2 |
Execution timed out |
5071 ms |
1884 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1880 KB |
Output is correct |
2 |
Execution timed out |
5071 ms |
1884 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1880 KB |
Output is correct |
2 |
Execution timed out |
5071 ms |
1884 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3160 KB |
Output is correct |
2 |
Correct |
4 ms |
1884 KB |
Output is correct |
3 |
Correct |
2 ms |
1884 KB |
Output is correct |
4 |
Correct |
8 ms |
3164 KB |
Output is correct |
5 |
Runtime error |
420 ms |
3532 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1880 KB |
Output is correct |
2 |
Execution timed out |
5071 ms |
1884 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3160 KB |
Output is correct |
2 |
Correct |
4 ms |
1884 KB |
Output is correct |
3 |
Correct |
2 ms |
1884 KB |
Output is correct |
4 |
Correct |
8 ms |
3164 KB |
Output is correct |
5 |
Runtime error |
420 ms |
3532 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1880 KB |
Output is correct |
2 |
Execution timed out |
5071 ms |
1884 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3160 KB |
Output is correct |
2 |
Correct |
4 ms |
1884 KB |
Output is correct |
3 |
Correct |
2 ms |
1884 KB |
Output is correct |
4 |
Correct |
8 ms |
3164 KB |
Output is correct |
5 |
Runtime error |
420 ms |
3532 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |