Submission #231839

# Submission time Handle Problem Language Result Execution time Memory
231839 2020-05-15T04:39:15 Z kshitij_sodani Kitchen (BOI19_kitchen) C++17
51 / 100
1000 ms 1024 KB
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define a first
#define b second
#define pb push_back
int n,m,k;
int aa[301];
int bb[301];
const int li=400*400;
int dp[li];
int su=0;
int ans2=-1;
int brute(int ind,int su2=0,int su3=0){
	if(ind==m){
		if(su2>=k*n and su3>=su){
			if(ans2==-1){
				ans2=su3-su;
			}
			else{
				ans2=min(ans2,su3-su);
			}
		}
	}
	else{
		brute(ind+1,su2,su3);
		brute(ind+1,su2+min(bb[ind],n),su3+bb[ind]);
	}

}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	memset(dp,0,sizeof(dp));
	dp[0]=1;
	cin>>n>>m>>k;
	int st=0;
	for(int i=0;i<n;i++){
		cin>>aa[i];
		su+=aa[i];
		if(aa[i]<k){
			st=1;
		}
	}
	
	int tt=0;
	for(int i=0;i<m;i++){
		cin>>bb[i];
		tt+=bb[i];
	}
	if(st){
		cout<<"Impossible"<<endl;
		return 0;
	}
	if(tt<su){
		cout<<"Impossible"<<endl;
		return 0;
	}
	if(k==1){
		for(int i=0;i<m;i++){
			for(int j=li;j>=bb[i];j--){
				dp[j]=max(dp[j],dp[j-bb[i]]);
			}
		}
		int ans=-1;
		for(int i=su;i<li;i++){
			if(dp[i]){
				ans=i-su;
				break;
			}
		}
		if(ans==-1){
			cout<<"Impossible"<<endl;
		}
		else{
			cout<<ans<<endl;
		}
	}
	else{
		brute(0);
		if(ans2==-1){
			cout<<"Impossible"<<endl;
		}
		else{
			cout<<ans2<<endl;
		}
	}














	return 0;
}

Compilation message

kitchen.cpp: In function 'int brute(int, int, int)':
kitchen.cpp:32:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 5 ms 896 KB Output is correct
2 Correct 6 ms 1024 KB Output is correct
3 Correct 5 ms 896 KB Output is correct
4 Correct 5 ms 1024 KB Output is correct
5 Correct 5 ms 1024 KB Output is correct
6 Correct 6 ms 896 KB Output is correct
7 Correct 5 ms 896 KB Output is correct
8 Correct 5 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 896 KB Output is correct
2 Correct 6 ms 1024 KB Output is correct
3 Correct 5 ms 896 KB Output is correct
4 Correct 5 ms 1024 KB Output is correct
5 Correct 5 ms 1024 KB Output is correct
6 Correct 6 ms 896 KB Output is correct
7 Correct 5 ms 896 KB Output is correct
8 Correct 5 ms 896 KB Output is correct
9 Correct 5 ms 896 KB Output is correct
10 Correct 5 ms 896 KB Output is correct
11 Correct 5 ms 896 KB Output is correct
12 Correct 5 ms 1024 KB Output is correct
13 Correct 5 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 1016 KB Output is correct
2 Correct 38 ms 1024 KB Output is correct
3 Correct 51 ms 1016 KB Output is correct
4 Correct 48 ms 1024 KB Output is correct
5 Correct 5 ms 1024 KB Output is correct
6 Correct 35 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1093 ms 896 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 896 KB Output is correct
2 Correct 6 ms 1024 KB Output is correct
3 Correct 5 ms 896 KB Output is correct
4 Correct 5 ms 1024 KB Output is correct
5 Correct 5 ms 1024 KB Output is correct
6 Correct 6 ms 896 KB Output is correct
7 Correct 5 ms 896 KB Output is correct
8 Correct 5 ms 896 KB Output is correct
9 Correct 5 ms 896 KB Output is correct
10 Correct 5 ms 896 KB Output is correct
11 Correct 5 ms 896 KB Output is correct
12 Correct 5 ms 1024 KB Output is correct
13 Correct 5 ms 1024 KB Output is correct
14 Correct 43 ms 1016 KB Output is correct
15 Correct 38 ms 1024 KB Output is correct
16 Correct 51 ms 1016 KB Output is correct
17 Correct 48 ms 1024 KB Output is correct
18 Correct 5 ms 1024 KB Output is correct
19 Correct 35 ms 1024 KB Output is correct
20 Execution timed out 1093 ms 896 KB Time limit exceeded
21 Halted 0 ms 0 KB -