Submission #874147

# Submission time Handle Problem Language Result Execution time Memory
874147 2023-11-16T10:45:05 Z vjudge1 Kitchen (BOI19_kitchen) C++17
0 / 100
19 ms 348 KB
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

const int MAXN = 300 + 5;

bool dp[MAXN * MAXN];

#define ONLINE_JUDGE
void solve() {
    int n, m, k;
    cin >> n >> m >> k;

    vector <int> a(n);
    for(int &i : a)
        cin >> i;

    vector <int> b(m);
    for(int &i : b)
        cin >> i;

    bool ans = (k <= m);
    for(int &i : a)
        ans &= (k <= i);

    int suma = accumulate(a.begin(), a.end(), 0);
    ans &= (suma <= accumulate(b.begin(), b.end(), 0));

    if(!ans) {
        return cout << "Impossible", void();
    }

    int cev = MAXN * MAXN;

    dp[0] = true;
    for(int i = 0; i < m; i++) {
        for(int j = b[i]; j < MAXN * MAXN; j++) {
            dp[j] |= dp[j - b[i]];
            if(i >= k -1 && j >= suma && dp[j - b[i]]) {
                cev = min(cev, j);
            }
        }
    }

    cout << cev - suma;
    
    return;
}

signed main() {
    #ifndef ONLINE_JUDGE
        freopen(".in", "r", stdin);
        freopen(".out", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int t = 1; //cin >> t;
    for(int i = 1; i <= t; i++) {
        solve();
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -