#pragma GCC optimize("O3", "inline")
#include <bits/stdc++.h>
using namespace std;
#define ins insert
#define pb push_back
#define int long long int
#define pii pair<int, int>
#define endl '\n'
#define drop(x) cout<<(x)<<endl; return;
#define all(x) x.begin(),x.end()
const int mod = 1e9 +7, sze = 1e5, inf = 2e18, prime = 23;
void mal(){
int n,m,k;
cin>>n>>m>>k;
vector<int> arr(n);
for(int i=0;i<n;i++){
cin>>arr[i];
}
vector<int> chefs(m);
for(int i=0;i<m;i++){
cin>>chefs[i];
}
if(m<=2){
multiset<int> lst;
int sum=0;
int sumb =0;
for(auto v:arr){
sum+=v;
}
for(auto v:chefs){
sumb+=v;
}
if(m==1){
if(sumb<sum || k>1){
drop("Impossible");
}
drop(sumb-sum);
}
else if(m==2){
// cout<<arr[0]<<" "<<arr[1]<<endl;
if(sumb<sum || k>2){
drop("Impossible");
}
if(k>=2){
int need=0;
for(auto &v:arr){
chefs[0]--;
chefs[1]--;
if(v<2 || chefs[0]<0 || chefs[1]<0){
drop("Impossible");
}
v-=2;
while(v--){
if(chefs[0]>chefs[1]){
chefs[0]--;
}
else{
chefs[1]--;
}
}
}
}
drop(chefs[0] + chefs[1]);
}
int ans = sumb - sum;
drop(ans);
return;
}
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
int tt = 1;
// cin>>tt;
while(tt--){
mal();
}
}
Compilation message
kitchen.cpp: In function 'void mal()':
kitchen.cpp:46:21: warning: unused variable 'need' [-Wunused-variable]
46 | int need=0;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |