Submission #448813

# Submission time Handle Problem Language Result Execution time Memory
448813 2021-08-01T19:28:24 Z julian33 Kitchen (BOI19_kitchen) C++14
0 / 100
1 ms 460 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {
    cerr<<vars<<" = ";
    string delim="";
    (...,(cerr<<delim<<values,delim=", "));
    cerr<<"\n";
}
#else
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {}
#endif

#define pb push_back
#define sz(x) (int)(x.size())
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> inline void maxa(T& a,T b){a=max(a,b);}
template<typename T> inline void mina(T& a,T b){a=min(a,b);} 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int mxN=2e3+5; //make sure this is right
const int mod=1e9+7;

/*
overall cost is a1 + a2 + a3 + ... + an
need at least k chefs to cover this cost with least amount of overflow
*/


int dp[mxN][2];
//dp[i] = max num of chefs to get cost of i

int main(){
    cin.sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    #ifdef LOCAL
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

    int n,m,k; cin>>n>>m>>k;
    int tot=0; int bad=0;
    for(int i=0;i<n;i++){
        int a; cin>>a;
        if(a<k)
            bad=1;
        tot+=a;
    }
    if(bad){
        cout<<"Impossible\n";
        return 0;
    }
    memset(dp,-1,sizeof(dp));
    dp[0][1]=0;
    for(int i=0;i<m;i++){
        int b; cin>>b;
        for(int j=0;j<=2*tot;j++){
            if(j>=b && ~dp[j-b][(i%2)^1])
                dp[j][(i%2)]=dp[j-b][(i%2)^1]+1;
            maxa(dp[j][(i%2)],dp[j][(i%2)^1]);
        }
    }
    for(int i=tot;i<=2*tot;i++){
        if(dp[i][(m-1)%2]>=k){
            cout<<i-tot<<"\n";
            return 0;
        }
    }
    cout<<"Impossible\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Incorrect 0 ms 332 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Incorrect 0 ms 332 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Incorrect 0 ms 332 KB Output isn't correct
5 Halted 0 ms 0 KB -