#include <bits/stdc++.h>
using namespace std;
const int nx=1e6+5, c=5e5;
#define ll long long
ll m, z, p[nx], n[nx], dp[nx], l;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>m>>l;
for (int i=m; i>=1; i--) cin>>n[i];
cin>>z;
for (int i=1; i<=m; i++) cin>>p[i];
for (int i=0; i<nx; i++) dp[i]=-1;
dp[c]=z;
for (int i=1; i<=m; i++)
{
for (int t=0; t<n[i]; t++)
{
for (int j=0; j<nx; j++)
{
if (j+i<nx&&dp[j+i]!=-1) dp[j]=max(dp[j], dp[j+i]+1);
}
}
}
for (int i=1; i<=m; i++)
{
for (int t=0; t<p[i]; t++)
{
for (int j=nx-1; j>=0; j--)
{
if (j-i>=0&&dp[j-i]!=-1) dp[j]=max(dp[j], dp[j-i]+1);
}
}
}
if (l+c<0||l+c>nx||dp[l+c]<1) cout<<"impossible";
else cout<<dp[l+c];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
8284 KB |
Output is correct |
2 |
Correct |
7 ms |
8300 KB |
Output is correct |
3 |
Correct |
7 ms |
8284 KB |
Output is correct |
4 |
Correct |
39 ms |
8284 KB |
Output is correct |
5 |
Correct |
1581 ms |
8280 KB |
Output is correct |
6 |
Correct |
1659 ms |
8280 KB |
Output is correct |
7 |
Correct |
684 ms |
8284 KB |
Output is correct |
8 |
Correct |
1681 ms |
8284 KB |
Output is correct |
9 |
Correct |
3041 ms |
8292 KB |
Output is correct |
10 |
Correct |
67 ms |
8284 KB |
Output is correct |
11 |
Correct |
58 ms |
8284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
8284 KB |
Output is correct |
2 |
Correct |
7 ms |
8300 KB |
Output is correct |
3 |
Correct |
7 ms |
8284 KB |
Output is correct |
4 |
Correct |
39 ms |
8284 KB |
Output is correct |
5 |
Correct |
1581 ms |
8280 KB |
Output is correct |
6 |
Correct |
1659 ms |
8280 KB |
Output is correct |
7 |
Correct |
684 ms |
8284 KB |
Output is correct |
8 |
Correct |
1681 ms |
8284 KB |
Output is correct |
9 |
Correct |
3041 ms |
8292 KB |
Output is correct |
10 |
Correct |
67 ms |
8284 KB |
Output is correct |
11 |
Correct |
58 ms |
8284 KB |
Output is correct |
12 |
Correct |
13 ms |
8280 KB |
Output is correct |
13 |
Correct |
7 ms |
8284 KB |
Output is correct |
14 |
Correct |
10 ms |
8284 KB |
Output is correct |
15 |
Correct |
40 ms |
8284 KB |
Output is correct |
16 |
Correct |
1614 ms |
8284 KB |
Output is correct |
17 |
Correct |
1833 ms |
8284 KB |
Output is correct |
18 |
Correct |
654 ms |
8284 KB |
Output is correct |
19 |
Correct |
1616 ms |
8280 KB |
Output is correct |
20 |
Correct |
3152 ms |
8284 KB |
Output is correct |
21 |
Correct |
67 ms |
8280 KB |
Output is correct |
22 |
Correct |
60 ms |
8284 KB |
Output is correct |
23 |
Execution timed out |
5076 ms |
8284 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
8280 KB |
Output is correct |
2 |
Execution timed out |
5083 ms |
8284 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
8280 KB |
Output is correct |
2 |
Execution timed out |
5083 ms |
8284 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
8280 KB |
Output is correct |
2 |
Execution timed out |
5083 ms |
8284 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
8284 KB |
Output is correct |
2 |
Correct |
7 ms |
8300 KB |
Output is correct |
3 |
Correct |
7 ms |
8284 KB |
Output is correct |
4 |
Correct |
39 ms |
8284 KB |
Output is correct |
5 |
Correct |
1581 ms |
8280 KB |
Output is correct |
6 |
Correct |
1659 ms |
8280 KB |
Output is correct |
7 |
Correct |
684 ms |
8284 KB |
Output is correct |
8 |
Correct |
1681 ms |
8284 KB |
Output is correct |
9 |
Correct |
3041 ms |
8292 KB |
Output is correct |
10 |
Correct |
67 ms |
8284 KB |
Output is correct |
11 |
Correct |
58 ms |
8284 KB |
Output is correct |
12 |
Correct |
40 ms |
8280 KB |
Output is correct |
13 |
Execution timed out |
5083 ms |
8284 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
8280 KB |
Output is correct |
2 |
Execution timed out |
5083 ms |
8284 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
8284 KB |
Output is correct |
2 |
Correct |
7 ms |
8300 KB |
Output is correct |
3 |
Correct |
7 ms |
8284 KB |
Output is correct |
4 |
Correct |
39 ms |
8284 KB |
Output is correct |
5 |
Correct |
1581 ms |
8280 KB |
Output is correct |
6 |
Correct |
1659 ms |
8280 KB |
Output is correct |
7 |
Correct |
684 ms |
8284 KB |
Output is correct |
8 |
Correct |
1681 ms |
8284 KB |
Output is correct |
9 |
Correct |
3041 ms |
8292 KB |
Output is correct |
10 |
Correct |
67 ms |
8284 KB |
Output is correct |
11 |
Correct |
58 ms |
8284 KB |
Output is correct |
12 |
Correct |
13 ms |
8280 KB |
Output is correct |
13 |
Correct |
7 ms |
8284 KB |
Output is correct |
14 |
Correct |
10 ms |
8284 KB |
Output is correct |
15 |
Correct |
40 ms |
8284 KB |
Output is correct |
16 |
Correct |
1614 ms |
8284 KB |
Output is correct |
17 |
Correct |
1833 ms |
8284 KB |
Output is correct |
18 |
Correct |
654 ms |
8284 KB |
Output is correct |
19 |
Correct |
1616 ms |
8280 KB |
Output is correct |
20 |
Correct |
3152 ms |
8284 KB |
Output is correct |
21 |
Correct |
67 ms |
8280 KB |
Output is correct |
22 |
Correct |
60 ms |
8284 KB |
Output is correct |
23 |
Execution timed out |
5076 ms |
8284 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
8280 KB |
Output is correct |
2 |
Execution timed out |
5083 ms |
8284 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
8284 KB |
Output is correct |
2 |
Correct |
7 ms |
8300 KB |
Output is correct |
3 |
Correct |
7 ms |
8284 KB |
Output is correct |
4 |
Correct |
39 ms |
8284 KB |
Output is correct |
5 |
Correct |
1581 ms |
8280 KB |
Output is correct |
6 |
Correct |
1659 ms |
8280 KB |
Output is correct |
7 |
Correct |
684 ms |
8284 KB |
Output is correct |
8 |
Correct |
1681 ms |
8284 KB |
Output is correct |
9 |
Correct |
3041 ms |
8292 KB |
Output is correct |
10 |
Correct |
67 ms |
8284 KB |
Output is correct |
11 |
Correct |
58 ms |
8284 KB |
Output is correct |
12 |
Correct |
13 ms |
8280 KB |
Output is correct |
13 |
Correct |
7 ms |
8284 KB |
Output is correct |
14 |
Correct |
10 ms |
8284 KB |
Output is correct |
15 |
Correct |
40 ms |
8284 KB |
Output is correct |
16 |
Correct |
1614 ms |
8284 KB |
Output is correct |
17 |
Correct |
1833 ms |
8284 KB |
Output is correct |
18 |
Correct |
654 ms |
8284 KB |
Output is correct |
19 |
Correct |
1616 ms |
8280 KB |
Output is correct |
20 |
Correct |
3152 ms |
8284 KB |
Output is correct |
21 |
Correct |
67 ms |
8280 KB |
Output is correct |
22 |
Correct |
60 ms |
8284 KB |
Output is correct |
23 |
Execution timed out |
5076 ms |
8284 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |