#include <bits/stdc++.h>
using namespace std;
const int NMAX=305;
int n,m,k,sum;
int a[NMAX],b[NMAX],dp[NMAX*NMAX+10];
int main()
{
ios_base::sync_with_stdio(false);
cin>>n>>m>>k;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++)
{
if(a[i]<k)
{
cout<<"Impossible"<<endl;
return 0;
}
sum+=a[i];
}
for(int j=1;j<=m;j++) cin>>b[j];
memset(dp, -NMAX*NMAX-1999, sizeof(dp));
dp[0]=0;
for(int i=1;i<=m;i++) for(int j=NMAX*NMAX;j>=b[i];j--)
{
dp[j]=max(dp[j],dp[j-b[i]]+min(n,b[i]));
}
for(int t=sum;t<=NMAX*NMAX;t++)
{
if(dp[t]>=n*k)
{
cout<<t-sum<<endl;
return 0;
}
}
cout<<"Impossible"<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
760 KB |
Output is correct |
2 |
Correct |
2 ms |
760 KB |
Output is correct |
3 |
Correct |
2 ms |
636 KB |
Output is correct |
4 |
Correct |
2 ms |
632 KB |
Output is correct |
5 |
Correct |
2 ms |
760 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
760 KB |
Output is correct |
2 |
Correct |
2 ms |
760 KB |
Output is correct |
3 |
Correct |
2 ms |
636 KB |
Output is correct |
4 |
Correct |
2 ms |
632 KB |
Output is correct |
5 |
Correct |
2 ms |
760 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
760 KB |
Output is correct |
9 |
Correct |
3 ms |
760 KB |
Output is correct |
10 |
Correct |
4 ms |
760 KB |
Output is correct |
11 |
Correct |
4 ms |
632 KB |
Output is correct |
12 |
Correct |
4 ms |
632 KB |
Output is correct |
13 |
Correct |
4 ms |
636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
632 KB |
Output is correct |
2 |
Correct |
22 ms |
632 KB |
Output is correct |
3 |
Correct |
31 ms |
660 KB |
Output is correct |
4 |
Correct |
30 ms |
760 KB |
Output is correct |
5 |
Correct |
28 ms |
760 KB |
Output is correct |
6 |
Correct |
21 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
760 KB |
Output is correct |
2 |
Correct |
6 ms |
760 KB |
Output is correct |
3 |
Correct |
6 ms |
760 KB |
Output is correct |
4 |
Correct |
7 ms |
760 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
760 KB |
Output is correct |
2 |
Correct |
2 ms |
760 KB |
Output is correct |
3 |
Correct |
2 ms |
636 KB |
Output is correct |
4 |
Correct |
2 ms |
632 KB |
Output is correct |
5 |
Correct |
2 ms |
760 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
760 KB |
Output is correct |
9 |
Correct |
3 ms |
760 KB |
Output is correct |
10 |
Correct |
4 ms |
760 KB |
Output is correct |
11 |
Correct |
4 ms |
632 KB |
Output is correct |
12 |
Correct |
4 ms |
632 KB |
Output is correct |
13 |
Correct |
4 ms |
636 KB |
Output is correct |
14 |
Correct |
25 ms |
632 KB |
Output is correct |
15 |
Correct |
22 ms |
632 KB |
Output is correct |
16 |
Correct |
31 ms |
660 KB |
Output is correct |
17 |
Correct |
30 ms |
760 KB |
Output is correct |
18 |
Correct |
28 ms |
760 KB |
Output is correct |
19 |
Correct |
21 ms |
760 KB |
Output is correct |
20 |
Correct |
6 ms |
760 KB |
Output is correct |
21 |
Correct |
6 ms |
760 KB |
Output is correct |
22 |
Correct |
6 ms |
760 KB |
Output is correct |
23 |
Correct |
7 ms |
760 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
21 ms |
632 KB |
Output is correct |
26 |
Correct |
24 ms |
632 KB |
Output is correct |
27 |
Correct |
16 ms |
676 KB |
Output is correct |
28 |
Correct |
24 ms |
760 KB |
Output is correct |
29 |
Correct |
24 ms |
632 KB |
Output is correct |
30 |
Correct |
29 ms |
632 KB |
Output is correct |