Submission #950776

# Submission time Handle Problem Language Result Execution time Memory
950776 2024-03-20T16:52:07 Z LCJLY Kitchen (BOI19_kitchen) C++14
100 / 100
55 ms 1912 KB
#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 dp[2][305*305];

void solve(){
	int n,m,k;
	cin >> n >> m >> k;
	
	int arr[n];
	int counter=0;
	bool amos=true;
	for(int x=0;x<n;x++){
		cin >> arr[x];
		counter+=arr[x];
		if(arr[x]<k) amos=false;
	}
	
	int chef[m];
	for(int x=0;x<m;x++){
		cin >> chef[x];
	}
	
	for(int x=0;x<305*305;x++){
		dp[0][x]=INT_MIN;
		dp[1][x]=INT_MIN;
	}
	dp[0][0]=0;
	
	
	for(int x=0;x<m;x++){
		for(int take=305*305-1;take>=0;take--){
			int nxt=take+chef[x];
			int add=dp[0][take]+min(chef[x],n);
			if(nxt<305*305){
				dp[1][nxt]=max(dp[1][nxt],add);
			}
			dp[1][take]=max(dp[1][take],dp[0][take]);
		}
		for(int take=0;take<305*305;take++){
			dp[0][take]=dp[1][take];
			dp[1][take]=INT_MIN;
		}
	}
	
	int ans=1e15;
	for(int x=0;x<305*305;x++){
		//if(x<15) cout << dp[0][x] << " ";
		if(x>=counter&&dp[0][x]>=n*k){
			ans=min(ans,x-counter);
		}
	}
	
	if(ans>1e9||!amos){
		cout << "Impossible\n";
	}
	else cout << ans;
}	

int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin >> t;
	while(t--){
		solve();
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1880 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 2 ms 1884 KB Output is correct
5 Correct 1 ms 1884 KB Output is correct
6 Correct 1 ms 1884 KB Output is correct
7 Correct 1 ms 1884 KB Output is correct
8 Correct 1 ms 1884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1880 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 2 ms 1884 KB Output is correct
5 Correct 1 ms 1884 KB Output is correct
6 Correct 1 ms 1884 KB Output is correct
7 Correct 1 ms 1884 KB Output is correct
8 Correct 1 ms 1884 KB Output is correct
9 Correct 4 ms 1912 KB Output is correct
10 Correct 3 ms 1884 KB Output is correct
11 Correct 3 ms 1912 KB Output is correct
12 Correct 3 ms 1884 KB Output is correct
13 Correct 4 ms 1884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 1884 KB Output is correct
2 Correct 43 ms 1892 KB Output is correct
3 Correct 52 ms 1892 KB Output is correct
4 Correct 55 ms 1880 KB Output is correct
5 Correct 48 ms 1900 KB Output is correct
6 Correct 35 ms 1880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1880 KB Output is correct
2 Correct 8 ms 1884 KB Output is correct
3 Correct 9 ms 1912 KB Output is correct
4 Correct 8 ms 1880 KB Output is correct
5 Correct 8 ms 1884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1880 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 2 ms 1884 KB Output is correct
5 Correct 1 ms 1884 KB Output is correct
6 Correct 1 ms 1884 KB Output is correct
7 Correct 1 ms 1884 KB Output is correct
8 Correct 1 ms 1884 KB Output is correct
9 Correct 4 ms 1912 KB Output is correct
10 Correct 3 ms 1884 KB Output is correct
11 Correct 3 ms 1912 KB Output is correct
12 Correct 3 ms 1884 KB Output is correct
13 Correct 4 ms 1884 KB Output is correct
14 Correct 43 ms 1884 KB Output is correct
15 Correct 43 ms 1892 KB Output is correct
16 Correct 52 ms 1892 KB Output is correct
17 Correct 55 ms 1880 KB Output is correct
18 Correct 48 ms 1900 KB Output is correct
19 Correct 35 ms 1880 KB Output is correct
20 Correct 8 ms 1880 KB Output is correct
21 Correct 8 ms 1884 KB Output is correct
22 Correct 9 ms 1912 KB Output is correct
23 Correct 8 ms 1880 KB Output is correct
24 Correct 8 ms 1884 KB Output is correct
25 Correct 38 ms 1884 KB Output is correct
26 Correct 41 ms 1896 KB Output is correct
27 Correct 27 ms 1880 KB Output is correct
28 Correct 42 ms 1884 KB Output is correct
29 Correct 43 ms 1892 KB Output is correct
30 Correct 50 ms 1884 KB Output is correct