Submission #1230733

#TimeUsernameProblemLanguageResultExecution timeMemory
1230733CrabCNHKitchen (BOI19_kitchen)C++20
100 / 100
23 ms1608 KiB
#include <bits/stdc++.h>

#define task     "BriantheCrab"

#define int    long long
#define pii    pair <int, int>
#define fi     first
#define se     second
#define szf    sizeof
#define sz(s)  (int)((s).size())
#define all(v) (v).begin(), (v).end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

template <class T> void minimize (T &t, T f) {if (t > f) t = f;}
template <class T> void maximize (T &t, T f) {if (t < f) t = f;}

const int maxN = 300 + 5;
const int inf = 1e18 + 7;
const int mod = 1e9 + 7;

// khong tu code thi khong kha len duoc dau

int a[maxN], b[maxN];
int dp[2][maxN * maxN];

void solve () {
    int n, m, k;
    cin >> n >> m >> k;
    int sumA = 0, sumB = 0;
    for (int i = 1; i <= n; i ++) {
        cin >> a[i];
        sumA += a[i];
        if (a[i] < k) {
            cout << "Impossible";
            return;
        }
    }
    for (int i = 1; i <= m; i ++) {
        cin >> b[i];
        sumB += b[i];
    }
    if (sumA > sumB) {
        cout << "Impossible";
        return;
    }
    for (int j = 0; j <= sumB; j ++) {
        dp[0][j] = dp[1][j] = -inf;
    }
    dp[0][0] = 0;
    for (int i = 1; i <= m; i ++) {
        int iL = i % 2;
        for (int j = 0; j <= sumB; j ++) {
            dp[iL][j] = dp[1 - iL][j];
            if (j >= b[i]) {
                maximize (dp[iL][j], dp[1 - iL][j - b[i]] + min (b[i], n));
            }
        }
        //cout << i << ' ' << sumB << ' ' << dp[iL][sumB] << '\n';
    }
    int res = inf;
    for (int j = 0; j <= sumB; j ++) {
        if (dp[m % 2][j] >= n * k && j >= sumA) {
            minimize (res, j - sumA);
        }
    }
    if (res == inf) {
        cout << "Impossible";
        return;
    }
    cout << res;
    return;
}

signed main () {
    cin.tie (nullptr) -> sync_with_stdio (false);
    if (fopen (task".inp", "r")) {
        freopen (task".inp", "r", stdin);
        freopen (task".out", "w", stdout);
    }
    int t = 1;
    //cin >> t;
    while (t --) {
        solve ();
    } 
    return 0;
}
// thfv 

Compilation message (stderr)

kitchen.cpp: In function 'int main()':
kitchen.cpp:82:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
kitchen.cpp:83:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |         freopen (task".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...