#include<bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int maxn=1e6+3;
const int mod=1e9+7;
int n, m, k, a[320], b[320];
int dp[320][10003];
ll a_sum=0, b_sum=0;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>m>>k;
for(int i=1; i<=n; i++){
cin>>a[i];
if(a[i]<k){
cout<<"Impossible";
return 0;
}
a_sum+=a[i];
}
for(int i=1; i<=m; i++){
cin>>b[i];
b_sum+=b[i];
}
memset(dp, -1, sizeof(dp));
dp[0][0]=0;
for(int i=1; i<=m; i++){
for(int j=1; j<=b_sum; j++){
dp[i][j]=dp[i-1][j];
if(b[i]<=j){
dp[i][j]=max(dp[i][j], dp[i-1][j-b[i]]+min(n, b[i]));
}
}
}
int ans=INT_MAX;
for(int j=a_sum; j<=b_sum; j++){
if(dp[m][j]>=n*k){
cout<<j-a_sum<<endl;
return 0;
}
}
cout<<"Impossible";
return 0;
}
Compilation message
kitchen.cpp: In function 'int main()':
kitchen.cpp:54:5: warning: unused variable 'ans' [-Wunused-variable]
54 | int ans=INT_MAX;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
12756 KB |
Output is correct |
2 |
Incorrect |
5 ms |
12756 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
12756 KB |
Output is correct |
2 |
Incorrect |
5 ms |
12756 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
26 ms |
12836 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
12744 KB |
Output is correct |
2 |
Correct |
5 ms |
12756 KB |
Output is correct |
3 |
Correct |
5 ms |
12752 KB |
Output is correct |
4 |
Correct |
5 ms |
12756 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
12756 KB |
Output is correct |
2 |
Incorrect |
5 ms |
12756 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |