제출 #950752

#제출 시각아이디문제언어결과실행 시간메모리
950752LCJLYKitchen (BOI19_kitchen)C++14
0 / 100
119 ms239188 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long 
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << "  " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << "  " << j << " " << #i << "  " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<int,int>pii;
typedef pair<pii,pii>pi2;
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

int arr[305];
int n,m,k;
int chef[305];
int memo[305][100005];

int dp(int index, int take){
	if(take>=k) return take-k;
	if(index==m) return INT_MAX;
	if(memo[index][take]!=-1) return memo[index][take];
	int ans=INT_MAX;
	ans=min(ans,dp(index+1,take));
	ans=min(ans,dp(index+1,take+chef[index]));
	return memo[index][take]=ans;
}

void solve(){
	cin >> n >> m >> k;
	
	int counter=0;
	for(int x=0;x<n;x++){
		cin >> arr[x];
		counter+=arr[x];
	}
	
	for(int x=0;x<m;x++){
		cin >> chef[x];
	}
	
	memset(memo,-1,sizeof(memo));
	int hold=dp(0,0);
	if(hold>1e8){
		cout << "Impossible\n";
	}
	else cout << hold;
}	

int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin >> t;
	while(t--){
		solve();
	}
}
#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...