Submission #1220244

#TimeUsernameProblemLanguageResultExecution timeMemory
1220244kokoxuyaKitchen (BOI19_kitchen)C++20
100 / 100
114 ms198724 KiB
#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();}

//impossible is not the same as 0 goodness gracious please properly tag your impossible cases gosh

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,maxsum=0;
	
	for(int a=1;a<=n;a++)
	{
		cin>>t1;
		if(t1<k){cout<<"Impossible";return 0;}
		sum+=t1;
	}
	
	vector<int>chefs(m+1);
	for(int a=1;a<=m;a++)
	{
		cin>>chefs[a];
		maxsum+=chefs[a];
	}
	
	if(maxsum<sum){cout<<"Impossible";return 0;}
	vector<vector<int>>dp(m+1,vector<int>(maxsum+1,LLONG_MIN));
	
	dp[0][0]=0;
	for(int a=1;a<=m;a++)
	{
		int curr=chefs[a];
		for(int b=0;b<curr;b++)
		{
			dp[a][b]=dp[a-1][b];
		}
		for(int b=curr;b<=maxsum;b++)
		{
			//if(a==m)debu2(a-1,b);
			dp[a][b]=max(dp[a-1][b],dp[a-1][b-curr]+min(curr,n));
		}
	}
	
	for(int a=sum;a<=maxsum;a++)
	{
		if(dp[m][a]>=(n*k))
		{
			//debu2(a,dp[m][a]);
			cout<<(a-sum);
			return 0;
		}
	}
	
	cout<<"Impossible";
}

//dp[chefno][sum]=maxdivnum (optimally high)
//-> m*n*ai
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...