#include <bits/stdc++.h>
using namespace std;
int mw, th=0, tw=0;
vector <int> food, chef;
int N, M, K;
int calc(int rh, int wh, int i)
{
int R=0, W=0;
W=chef[i];
if(W>N)
{
R+=W-N;
W=N;
}
if(W+wh>mw)
{
R+=W-mw;
W=mw;
}
wh+=W;
rh+=R;
if(wh==mw && rh>=th)
{
cout<<rh<<" "<<wh<<" "<<i<<"\n";
return rh-th;
}
int mi=tw;
cout<<rh<<" "<<wh<<" "<<i<<"\n";
for(int j=i+1; j<M; ++j)
{
int littler=calc(rh, wh, j);
if(mi>littler)
{
mi=littler;
}
}
return mi;
}
int main()
{
cin>>N>>M>>K;
food.resize(N);
chef.resize(M);
for(int i=0; i<N; ++i)
{
cin>>food[i];
}
for(int i=0; i<M; ++i)
{
cin>>chef[i];
}
sort(food.begin(), food.end());
sort(chef.begin(), chef.end());
for(int i=0; i<N; ++i)
{
if(food[i]<K)
{
cout<<"Impossible";
return 0;
}
th+=food[i];
}
mw=N*K;
for(int i=0; i<M; ++i)
{
tw+=chef[i];
}
if(th>tw)
{
cout<<"Impossible";
return 0;
}
if(M<K)
{
cout<<"Impossible";
return 0;
}
th-=mw;
cout<<calc(0, 0, 0);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |