Submission #1005617

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

using namespace std;

const int sz = 1e3 + 3;

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;
    }

    int S = accumulate(b + 1, b + 1 + m, (int)0)+1;
    int T = accumulate(a + 1, a + 1 + n, (int)0);
    int dp[S];
    for (int j=0; j<=S; j++) {
        dp[j] = -1;
    }
    dp[0] = 0;
    for (int i=1; i<=m; i++) {
        int val = b[i]; 
        for (int j=S; j>=val; j--) {
            if (dp[j-val]!=-1) {
                dp[j] = max(dp[j],dp[j-val]+min(n,val));
            }
        }
    }
    int ans = -1;
    for (int i=T; i<=S; i++) {
        //cout << i <<" " << dp[i] << endl;
        if (dp[i]>=n*k) {
            ans=i-T;
            break;
        }
    }
    if (ans==-1) {
        cout << "Impossible" << endl;
    }
    else {
        cout << ans << endl;
    }
}
#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...