#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=0; 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 |
Correct |
5 ms |
12756 KB |
Output is correct |
3 |
Correct |
5 ms |
12756 KB |
Output is correct |
4 |
Correct |
5 ms |
12756 KB |
Output is correct |
5 |
Correct |
5 ms |
12740 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
5 ms |
12756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
12756 KB |
Output is correct |
2 |
Correct |
5 ms |
12756 KB |
Output is correct |
3 |
Correct |
5 ms |
12756 KB |
Output is correct |
4 |
Correct |
5 ms |
12756 KB |
Output is correct |
5 |
Correct |
5 ms |
12740 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
5 ms |
12756 KB |
Output is correct |
9 |
Correct |
5 ms |
12756 KB |
Output is correct |
10 |
Correct |
5 ms |
12756 KB |
Output is correct |
11 |
Correct |
5 ms |
12756 KB |
Output is correct |
12 |
Correct |
6 ms |
12756 KB |
Output is correct |
13 |
Incorrect |
5 ms |
12756 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
27 ms |
12852 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
12764 KB |
Output is correct |
2 |
Correct |
5 ms |
12756 KB |
Output is correct |
3 |
Correct |
5 ms |
12756 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 |
Correct |
5 ms |
12756 KB |
Output is correct |
3 |
Correct |
5 ms |
12756 KB |
Output is correct |
4 |
Correct |
5 ms |
12756 KB |
Output is correct |
5 |
Correct |
5 ms |
12740 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
5 ms |
12756 KB |
Output is correct |
9 |
Correct |
5 ms |
12756 KB |
Output is correct |
10 |
Correct |
5 ms |
12756 KB |
Output is correct |
11 |
Correct |
5 ms |
12756 KB |
Output is correct |
12 |
Correct |
6 ms |
12756 KB |
Output is correct |
13 |
Incorrect |
5 ms |
12756 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |