#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define ss second
#define ff first
#define piii pair<int,pii>
#define debu(x) (cerr << #x << " = "<< x << "\n")
#define debu2(x,y) (cerr << #x << " = "<< x << " " << #y << " = " << y << "\n")
#define debu3(x,y,z) (cerr << #x << " = "<< x << " " << #y << " = " << y << " " << #z << " = " << z<< "\n")
#define bitout(x,y) {\
cerr << #x << " : ";\
for (int justforbits = y; justforbits >=0; justforbits--)cout << (((1 << justforbits) & x)>=1);\
cout << "\n";\
}
#define rangeout(j,rangestart,rangeend) {\
cerr << "outputting" << #j<< ":\n";\
for (int forrang = rangestart; forrang <= rangeend; forrang++)cerr << j[forrang] << " ";\
cerr<<"\n";\
}
#define c1 {cerr << "Checkpoint 1! \n\n";cerr.flush();}
#define c2 {cerr << "Checkpoint 2! \n\n";cerr.flush();}
#define c3 {cerr << "Checkpoint 3! \n\n";cerr.flush();}
#define c4 {cerr << "Checkpoint 4! \n\n";cerr.flush();}
signed main()
{
int t1,t2,t3,t4;
mt19937_64 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
//ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n,m,k;cin>>n>>m>>k;
int sum=0;
for(int a=1;a<=n;a++)
{
cin>>t1;
sum+=t1;
if(t1<k){cout<<"Impossible";return 0;}
}
vector<int>nummys(m);
for(int a=0;a<m;a++)
{
cin>>nummys[a];
}
int bs=1;
for(int a=1;a<=m;a++)bs*=2;
bs--;
int ans=LLONG_MAX;
for(int i=1;i<=bs;i++)
{
priority_queue<int>chefs;
int cs=0;
for (int ii=0;ii<m;ii++)
{
if((1<<ii)&bs)
{
chefs.push(nummys[ii]);
cs+=nummys[ii];
}
}
if(cs<sum)continue;
bool troo=true;
for(int a=1;a<=n;a++)
{
if(chefs.size()<k){troo=false;break;}
vector<int>tbp;
for(int b=1;b<=k;b++)
{
t1=chefs.top()-1;
chefs.pop();
tbp.pb(t1);
}
for(int x:tbp)
{
chefs.push(x);
}
}
if(troo)ans=min(ans,cs-sum);
}
if(ans==LLONG_MAX)cout<<"Impossible";
else cout<<ans;
}
# | 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... |