제출 #444785

#제출 시각아이디문제언어결과실행 시간메모리
444785zxcvbnmKitchen (BOI19_kitchen)C++14
31 / 100
7 ms316 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9 + 5;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(n), b(m);
    for(int& i : a) {
        cin >> i;
    }
    for(int& i : b) {
        cin >> i;
    }

    int time = accumulate(a.begin(), a.end(), 0);
    int ans = INF;
    for(int mask = 0; mask < (1 << m); mask++) {
        vector<int> chefs;
        if (__builtin_popcount(mask) < k) continue;
        for(int i = 0; i < m; i++) {
            if (mask & (1 << i)) {
                chefs.push_back(b[i]);
            }
        }

        int sum = accumulate(chefs.begin(), chefs.end(), 0);
        if (sum < time || ans < sum-time) continue;

        bool ok = true;
        for(int i = 0; i < n && ok; i++) {
            if (a[i] < k) {
                ok = false;
                break;
            }
            sort(chefs.rbegin(), chefs.rend());
            for(int j = 0; j < k; j++) {
                if (chefs[j] <= 0) {
                    ok = false;
                    break;
                }
                chefs[j]--;
            }
        }

        if (ok) {
            ans = sum-time;
        }
    }

    if (ans == INF) {
        cout << "Impossible\n";
    } else {
        cout << ans << "\n";
    }
    return 0;
}
#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...