Submission #444798

# Submission time Handle Problem Language Result Execution time Memory
444798 2021-07-15T10:56:05 Z zxcvbnm Kitchen (BOI19_kitchen) C++14
0 / 100
1 ms 588 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9 + 5;
const int maxN = 45;
bool dp1[maxN][maxN*maxN];
bool dp2[maxN][maxN*maxN];
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 ans = INF;
    for(int i : a) {
        if (i < k) {
            cout << "Impossible\n";
            exit(0);
        }
    }

    int time = accumulate(a.begin(), a.end(), 0);
    vector<int> small, big;
    for(int i : b) {
        if (i <= n) {
            small.push_back(i);
        } else {
            big.push_back(i);
        }
    }

    dp1[0][0] = true;
    int sn = small.size();
    for(int i = 1; i <= sn; i++) {
        for(int j = 0; j < maxN*maxN; j++) {
            dp1[i][j] |= dp1[i-1][j];
            if (j-small[i-1] < 0) continue;

            dp1[i][j] |= dp1[i-1][j-small[i-1]];
        }
    }

    vector<int> sums;
    for(int j = 0; j < maxN*maxN; j++) {
        if (dp1[sn][j]) {
            sums.push_back(j);
        }
    }

    dp2[0][0] = true;
    int bn = big.size();
    for(int i = 1; i <= bn; i++) {
        for(int j = 0; j < maxN*maxN; j++) {
            dp2[i][j] |= dp2[i-1][j];
            if (j-big[i-1] < 0) continue;

            dp2[i][j] |= dp2[i-1][j-big[i-1]];
            if (dp2[i][j]) {
                int need = max((k-i) * n, time-j);
                auto it = lower_bound(sums.begin(), sums.end(), need);
                if (it != sums.end()) {
                    ans = min(ans, (j+*it)-time);
                }
            }
        }
    }

    if (ans == INF) {
        cout << "Impossible\n";
    } else {
        cout << ans << "\n";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Incorrect 0 ms 204 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Incorrect 0 ms 204 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 588 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Incorrect 0 ms 204 KB Output isn't correct
5 Halted 0 ms 0 KB -