/*
k=1
*/
#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;
int mn = inf;
multiset<int> var[sze+1];
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(k>m){
drop("Impossible");
}
if(m==1){
for(auto v:arr){
chefs[0]-=v;
if(chefs[0]<0){
drop("Impossible");
}
}
drop(chefs[0]);
}
else{
if(k==1){
int ans=0;
for(auto &v:arr){
while(v){
sort(all(chefs),greater<int>());
if(!chefs[0]){
drop("Impossible");
}
if(chefs[0]){
v--;
chefs[0]--;
}
if(chefs[1]){
v--;
chefs[1]--;
}
}
}
drop(chefs[0]+chefs[1]);
}
else{
int ans=0;
for(auto& v:arr){
if(v<2){
drop("Impossible");
}
if(!chefs[0] || chefs[1]){
drop("Impossible");
}
v-=chefs[0];
v-=chefs[1];
chefs[0]--;
chefs[1]--;
while(v){
sort(all(chefs),greater<int>());
if(!chefs[0]){
drop("Impossible");
}
v--;
chefs[0]--;
if(chefs[1]){
if(v){
v--;
chefs[1]--;
}
else{
ans++;
}
}
}
}
drop(chefs[0]+chefs[1]);
}
}
}
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:45:17: warning: unused variable 'ans' [-Wunused-variable]
45 | int ans=0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
4956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
4956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
35 ms |
4952 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
4956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
4956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |