답안 #530125

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
530125 2022-02-24T16:30:10 Z fatemetmhr Kitchen (BOI19_kitchen) C++17
100 / 100
26 ms 1112 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb     push_back
#define fi     first
#define se     second
#define all(x) x.begin(), x.end()

const int maxn5 = 7e3 + 10;
const ll  inf   = 1e18;
const int masum = 1e5 + 10;

ll a[maxn5], b[maxn5];
ll n, m, k;
ll dp[masum];

inline void solve(){
	fill(dp, dp + masum, -inf);
	dp[0] = 0;
	for(int i = 0; i < m; i++){
		for(int j = masum - 1; j >= b[i]; j--){
			dp[j] = max(dp[j], dp[j - b[i]] + min(n, b[i]));
		}
	}
	ll sum = 0;
	for(int i = 0; i < n; i++)
		sum += a[i];
	for(int i = sum; i < masum; i++) if(dp[i] >= n * k){
		cout << i - sum << '\n';
		exit(0);
	}
	cout << "Impossible" << endl;
	exit(0);
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	

	cin >> n >> m >> k;
	ll sum = 0;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		if(a[i] < k)
			return cout << "Impossible" << endl, 0;
		sum += a[i];
	}
	for(int i = 0; i < m; i++)
		cin >> b[i];
	if(true)
		solve();
	ll ans = inf;
	for(int mask = 0; mask < (1 << m); mask++) if(__builtin_popcount(mask) >= k){
		ll sum1 = 0, sum2 = 0;
		for(int i = 0; i < m; i++) if((mask >> i)&1){
			sum1 += min(n, b[i]);
			sum2 += b[i];
		}
		if(sum1 >= n * k && sum2 >= sum && ans >= sum2){
			ans = sum2;
			//cout << mask << ' ' << sum1 << ' ' << sum2 << endl;
		}
	}
	if(ans == inf)
		cout << "Impossible" << endl;
	else
		cout << ans - sum << endl;
}
















# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 1088 KB Output is correct
3 Correct 1 ms 1100 KB Output is correct
4 Correct 1 ms 1088 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 1100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 1088 KB Output is correct
3 Correct 1 ms 1100 KB Output is correct
4 Correct 1 ms 1088 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 1100 KB Output is correct
9 Correct 4 ms 1088 KB Output is correct
10 Correct 2 ms 1100 KB Output is correct
11 Correct 2 ms 1100 KB Output is correct
12 Correct 2 ms 1100 KB Output is correct
13 Correct 2 ms 1100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 1112 KB Output is correct
2 Correct 21 ms 1108 KB Output is correct
3 Correct 26 ms 1108 KB Output is correct
4 Correct 25 ms 1108 KB Output is correct
5 Correct 26 ms 1100 KB Output is correct
6 Correct 19 ms 1092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1088 KB Output is correct
2 Correct 4 ms 1104 KB Output is correct
3 Correct 5 ms 1104 KB Output is correct
4 Correct 6 ms 1100 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 1088 KB Output is correct
3 Correct 1 ms 1100 KB Output is correct
4 Correct 1 ms 1088 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 1100 KB Output is correct
9 Correct 4 ms 1088 KB Output is correct
10 Correct 2 ms 1100 KB Output is correct
11 Correct 2 ms 1100 KB Output is correct
12 Correct 2 ms 1100 KB Output is correct
13 Correct 2 ms 1100 KB Output is correct
14 Correct 23 ms 1112 KB Output is correct
15 Correct 21 ms 1108 KB Output is correct
16 Correct 26 ms 1108 KB Output is correct
17 Correct 25 ms 1108 KB Output is correct
18 Correct 26 ms 1100 KB Output is correct
19 Correct 19 ms 1092 KB Output is correct
20 Correct 5 ms 1088 KB Output is correct
21 Correct 4 ms 1104 KB Output is correct
22 Correct 5 ms 1104 KB Output is correct
23 Correct 6 ms 1100 KB Output is correct
24 Correct 0 ms 208 KB Output is correct
25 Correct 19 ms 1104 KB Output is correct
26 Correct 22 ms 1104 KB Output is correct
27 Correct 15 ms 1104 KB Output is correct
28 Correct 21 ms 1104 KB Output is correct
29 Correct 22 ms 1104 KB Output is correct
30 Correct 26 ms 1104 KB Output is correct