Submission #874149

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

const int MAXN = 300 + 5;

int 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();
    }

    dp[0] = 0;
    for(int i = 0; i < m; i++) {
        for(int j = MAXN * MAXN -1; j >= b[i]; j--) {
            dp[j] = max(dp[j], dp[j - b[i]] +1);
        }
    }

    int cev = MAXN * MAXN +1;
    for(int i = MAXN * MAXN -1; i >= suma; i--) {
        if(dp[i] >= k) {
            cev = i;
        }
    }

    if(cev == MAXN * MAXN +1)
        cout << "Impossible";
    else 
        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 856 KB Output is correct
2 Incorrect 1 ms 604 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 856 KB Output is correct
2 Incorrect 1 ms 604 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 856 KB Output is correct
2 Incorrect 1 ms 604 KB Output isn't correct
3 Halted 0 ms 0 KB -