#include <iostream>
using namespace std;
const int N=301;
int a[N],b[N],c[N];
int dp[(N-1)*N];
signed main()
{
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int n,m,k;
cin>>n>>m>>k;
int s1=0;
int s2=n*k;
for(int i=0;i<n;i++)
{
cin>>a[i];
if(a[i]<k)
{
cout<<"Impossible\n";
exit(0);
}
s1+=a[i];
}
int mx=300*300;
for(int j=0;j<=mx;j++)
dp[j]=-1e9;
dp[0]=0;
int ans=-1;
for(int j=0;j<m;j++)
{
cin>>b[j];
c[j]=min(n,b[j]);
}
for(int j=0;j<m;j++)
{
for(int s3=mx-b[j];s3>=0;s3--)
{
dp[s3+b[j]]=max(dp[s3+b[j]],dp[s3]+c[j]);
}
}
for(int s3=s1;s3<=mx;s3++)
if(dp[s3]>=s2)
{
cout<<s3-s1<<'\n';
return 0;
}
cout<<"Impossible\n";
}
Compilation message
kitchen.cpp: In function 'int main()':
kitchen.cpp:29:9: warning: unused variable 'ans' [-Wunused-variable]
29 | int ans=-1;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
1 ms |
856 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
1 ms |
856 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
644 KB |
Output is correct |
13 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
604 KB |
Output is correct |
2 |
Correct |
15 ms |
856 KB |
Output is correct |
3 |
Correct |
20 ms |
940 KB |
Output is correct |
4 |
Correct |
22 ms |
604 KB |
Output is correct |
5 |
Correct |
19 ms |
604 KB |
Output is correct |
6 |
Correct |
14 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
604 KB |
Output is correct |
2 |
Correct |
3 ms |
604 KB |
Output is correct |
3 |
Correct |
3 ms |
604 KB |
Output is correct |
4 |
Correct |
3 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
1 ms |
856 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
644 KB |
Output is correct |
13 |
Correct |
1 ms |
600 KB |
Output is correct |
14 |
Correct |
19 ms |
604 KB |
Output is correct |
15 |
Correct |
15 ms |
856 KB |
Output is correct |
16 |
Correct |
20 ms |
940 KB |
Output is correct |
17 |
Correct |
22 ms |
604 KB |
Output is correct |
18 |
Correct |
19 ms |
604 KB |
Output is correct |
19 |
Correct |
14 ms |
604 KB |
Output is correct |
20 |
Correct |
3 ms |
604 KB |
Output is correct |
21 |
Correct |
3 ms |
604 KB |
Output is correct |
22 |
Correct |
3 ms |
604 KB |
Output is correct |
23 |
Correct |
3 ms |
604 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
14 ms |
812 KB |
Output is correct |
26 |
Correct |
17 ms |
604 KB |
Output is correct |
27 |
Correct |
12 ms |
604 KB |
Output is correct |
28 |
Correct |
20 ms |
808 KB |
Output is correct |
29 |
Correct |
18 ms |
812 KB |
Output is correct |
30 |
Correct |
20 ms |
812 KB |
Output is correct |