Submission #464471

# Submission time Handle Problem Language Result Execution time Memory
464471 2021-08-13T09:25:21 Z Khizri Kitchen (BOI19_kitchen) C++17
0 / 100
1000 ms 2112 KB
#include <bits/stdc++.h>
using namespace std;
//------------------------------DEFINE------------------------------
//******************************************************************
#define IOS ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0)
#define ll long long
#define pb push_back		 
#define F first																 
#define S second 															 
#define INF 1e18
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define OK cout<<"Ok"<<endl;
#define MOD (ll)(1e9+7)
#define endl "\n"
//******************************************************************
//----------------------------FUNCTION------------------------------
//******************************************************************
ll gcd(ll a,ll b){
	if(a>b) swap(a,b);
	if(a==0) return a+b;
	return gcd(b%a,a);
}
ll lcm(ll a,ll b){
	return a/gcd(a,b)*b;
}
bool is_prime(ll n){
	ll k=sqrt(n);
	if(n==2) return true;
	if(n<2||n%2==0||k*k==n) return false;
	for(int i=3;i<=k;i+=2){
		if(n%i==0){
			return false;
		}
	}
	return true;
}
//*****************************************************************
//--------------------------MAIN-CODE------------------------------
const int mxn=2e5+5;
int t=1,n,m,k,arr[mxn],b[mxn],sum,x;
bool q=false;
void solve(){
	cin>>m>>n>>k;
	for(int i=1;i<=m;i++){
		cin>>b[i];
		sum+=b[i];
		if(b[i]<k){
			q=true;
		}
	}
	for(int i=1;i<=n;i++){
		cin>>arr[i];
		x+=arr[i];
	}
	if(n<k||x<sum){
		q=true;
	}
	if(q){
		cout<<"Impossible"<<endl;
		return;
	}
	int ans=0,cur=0,say=0;
	sort(arr+1,arr+n+1);
	for(int ind=1;ind<=m;ind++){
		int sum=b[ind];
		if(sum<=cur&&say>=k){
			cur-=sum;
			say-=k;
		}
		map<int,int>mp;
		mp[0]=0;
		for(int i=1;i<=n;i++){
			vector<pii>vt;
			for(auto it=mp.begin();it!=mp.end();it++){
				vt.pb({it->F+arr[i],it->S+1});
			}
			for(pii v:vt){
				mp[v.F]=max(mp[v.F],v.S);
			}
		}
		int ans=1e7;
		for(auto it=mp.begin();it!=mp.end();it++){
			if(it->F>=sum-cur&&it->S>=max(0,k-say)){
				ans=min(ans,(it->F)-sum);
			}
		}
		if(ans==1e7){
			cout<<"Impossible"<<endl;
			return;
		}
		cur+=ans;
		say+=min(k,ans);
	}
	cout<<cur;
}
int main(){
	IOS;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Compilation message

kitchen.cpp: In function 'void solve()':
kitchen.cpp:65:6: warning: unused variable 'ans' [-Wunused-variable]
   65 |  int ans=0,cur=0,say=0;
      |      ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1091 ms 2112 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 59 ms 420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -