답안 #231836

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
231836 2020-05-15T04:36:31 Z kshitij_sodani Kitchen (BOI19_kitchen) C++17
20 / 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],k),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 or m<k){
		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]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 896 KB Output is correct
2 Correct 5 ms 896 KB Output is correct
3 Correct 5 ms 896 KB Output is correct
4 Incorrect 5 ms 1024 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 896 KB Output is correct
2 Correct 5 ms 896 KB Output is correct
3 Correct 5 ms 896 KB Output is correct
4 Incorrect 5 ms 1024 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 1016 KB Output is correct
2 Correct 38 ms 896 KB Output is correct
3 Correct 47 ms 896 KB Output is correct
4 Correct 49 ms 1016 KB Output is correct
5 Correct 5 ms 896 KB Output is correct
6 Correct 38 ms 1016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1087 ms 896 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 896 KB Output is correct
2 Correct 5 ms 896 KB Output is correct
3 Correct 5 ms 896 KB Output is correct
4 Incorrect 5 ms 1024 KB Output isn't correct
5 Halted 0 ms 0 KB -