Submission #1005611

#TimeUsernameProblemLanguageResultExecution timeMemory
1005611coolboy19521Kitchen (BOI19_kitchen)C++17
0 / 100
20 ms1196 KiB
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
#define int long long

using namespace std;

const int sz = 3e2 + 6;

int a[sz], b[sz];
int dp[sz * sz];

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    int n, m, k;
    cin >> n >> m >> k;

    int sm = 0;
    bool f = false;

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        sm += a[i];

        if (a[i] < k) {
            f = true;
        }
    }

    for (int i = 1; i <= m; i++) {
        cin >> b[i];
    }

    if (f) {
        cout << "IMPOSSIBLE";
        return 0;
    }

    fill(dp, dp + sz * sz, -1);
    dp[0] = 0;

    int s = accumulate(a + 1, a + n + 1, 0);
    int t = accumulate(b + 1, b + m + 1, 0);

    for (int i = 1; i <= m; i++) {
        for (int j = t; j > b[i]; j--) {
            if (dp[j - b[i]] != -1) {
                dp[j] = max(dp[j], dp[j - b[i]] + min(b[i], n));
            }
        }
        dp[b[i]] = max(dp[b[i]], min(b[i], n));
    }

    for (int i = s; i <= t; i++) {
        if (dp[i] >= n * k) {
            cout << i - sm;
            return 0;
        }
    }

    cout << "IMPOSSIBLE";
}
#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...