Submission #584204

# Submission time Handle Problem Language Result Execution time Memory
584204 2022-06-27T03:45:30 Z amunduzbaev Kitchen (BOI19_kitchen) C++17
0 / 100
2 ms 348 KB
#include "bits/stdc++.h"
using namespace std;
 
#define ar array
typedef int64_t ll;
//~ #define int ll

const int N = 305;
int a[N], b[N];
bitset<N * N> dp;

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	int n, m, k; cin>>n>>m>>k;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i] < k){
			cout<<"impossible\n";
			return 0;
		}
	}
	for(int i=0;i<m;i++){
		cin>>b[i];
	}
	
	int sum = accumulate(a, a + n, 0);
	sort(b, b + m);
	int l = m, tot = 0;
	dp[0] = 1;
	for(int i=0;i<m;i++){
		if(b[i] > n) { l = i; break; }
		tot += b[i];
		dp |= (dp << b[i]);
	}
	
	int rem = 0, res = 1e9;
	for(int i=0;i<=k && l <= m;i++){
		for(int j=max(sum - rem, (k - i) * n);j<=tot;j++){
			if(dp[j]){
				res = min(res, rem + j - sum);
			}
		}
		
		rem += b[l++];
	}
	
	if(res == 1e9) cout<<"impossible\n";
	else cout<<res<<"\n";
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 0 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 0 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Incorrect 2 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Incorrect 0 ms 340 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 0 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -