Submission #1004246

# Submission time Handle Problem Language Result Execution time Memory
1004246 2024-06-21T06:47:56 Z HasanV11010238 Kitchen (BOI19_kitchen) C++17
0 / 100
73 ms 163664 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 10000000
int main(){
    ll n, m, k, su = 0, bsu = 0;
    cin>>n>>m>>k;
    bool ca = 0;
    if (m < k){
        ca = 1;
    }
    vector<ll> a(n + 1), b(m + 1);
    for (int i = 0;  i< n; i++){
        cin>>a[i + 1];
        su += a[i + 1];
        if (a[i + 1] < k){
            ca = 1;
        }
    }
    for (int i = 0; i < m; i++){
        cin>>b[i + 1];
        bsu += b[i + 1];
    }
    if (ca || bsu < su){
        cout<<"Impossible";
        return 0;
    }
    vector<vector<vector<ll>>> dp(m + 1, vector<vector<ll>>(m + 1, vector<ll>(k * n + 1, 0)));
    for (int i = 1; i <= m; i++){
        for (int j = 1; j <= i; j++){
            for (ll l = (i - 1) * k; l <= k * n; l++){
                for (int r = 0; r <= k; r++){
                    if (a[j] >= r){
                        dp[i][j][l] = max(dp[i - 1][j - 1][l - r] + a[j] - r, dp[i - 1][j][l]);
                    }
                    else{
                        dp[i][j][l] = max(dp[i - 1][j - 1][l - a[j]], dp[i - 1][j][l]);
                    }
                }
            }
        }
    }
    ll ans = m + 1;
    for (ll i = k; i <= m; i++){
        ll val = max(ans, dp[m][i][k * n]);
        if (val >= su - k * i){
            ans = min(ans, i);
        }
    }
    cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 73 ms 163664 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 10844 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -