Submission #448816

# Submission time Handle Problem Language Result Execution time Memory
448816 2021-08-01T19:37:37 Z julian33 Kitchen (BOI19_kitchen) C++14
100 / 100
98 ms 1876 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=2e5+5; //make sure this is right
const int mod=1e9+7;

int dp[mxN][2];

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));
    int lim=m<=15?tot+1000:2*tot;
    dp[0][1]=0;
    for(int i=0;i<m;i++){
        int b; cin>>b;
        for(int j=0;j<=lim;j++){
            if(j>=b && ~dp[j-b][(i%2)^1])
                dp[j][(i%2)]=dp[j-b][(i%2)^1]+min(n,b);
            maxa(dp[j][(i%2)],dp[j][(i%2)^1]);
        }
    }
    for(int i=tot;i<=lim;i++){
        if(dp[i][(m-1)%2]>=k*n){
            cout<<i-tot<<"\n";
            return 0;
        }
    }
    cout<<"Impossible\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1768 KB Output is correct
2 Correct 1 ms 1868 KB Output is correct
3 Correct 1 ms 1868 KB Output is correct
4 Correct 1 ms 1868 KB Output is correct
5 Correct 1 ms 1868 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 1868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1768 KB Output is correct
2 Correct 1 ms 1868 KB Output is correct
3 Correct 1 ms 1868 KB Output is correct
4 Correct 1 ms 1868 KB Output is correct
5 Correct 1 ms 1868 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 1868 KB Output is correct
9 Correct 1 ms 1868 KB Output is correct
10 Correct 1 ms 1868 KB Output is correct
11 Correct 1 ms 1868 KB Output is correct
12 Correct 1 ms 1772 KB Output is correct
13 Correct 1 ms 1868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 1868 KB Output is correct
2 Correct 45 ms 1868 KB Output is correct
3 Correct 55 ms 1868 KB Output is correct
4 Correct 86 ms 1868 KB Output is correct
5 Correct 98 ms 1868 KB Output is correct
6 Correct 42 ms 1868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1868 KB Output is correct
2 Correct 2 ms 1868 KB Output is correct
3 Correct 1 ms 1868 KB Output is correct
4 Correct 1 ms 1868 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1768 KB Output is correct
2 Correct 1 ms 1868 KB Output is correct
3 Correct 1 ms 1868 KB Output is correct
4 Correct 1 ms 1868 KB Output is correct
5 Correct 1 ms 1868 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 1868 KB Output is correct
9 Correct 1 ms 1868 KB Output is correct
10 Correct 1 ms 1868 KB Output is correct
11 Correct 1 ms 1868 KB Output is correct
12 Correct 1 ms 1772 KB Output is correct
13 Correct 1 ms 1868 KB Output is correct
14 Correct 55 ms 1868 KB Output is correct
15 Correct 45 ms 1868 KB Output is correct
16 Correct 55 ms 1868 KB Output is correct
17 Correct 86 ms 1868 KB Output is correct
18 Correct 98 ms 1868 KB Output is correct
19 Correct 42 ms 1868 KB Output is correct
20 Correct 1 ms 1868 KB Output is correct
21 Correct 2 ms 1868 KB Output is correct
22 Correct 1 ms 1868 KB Output is correct
23 Correct 1 ms 1868 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 42 ms 1868 KB Output is correct
26 Correct 49 ms 1868 KB Output is correct
27 Correct 17 ms 1868 KB Output is correct
28 Correct 54 ms 1876 KB Output is correct
29 Correct 54 ms 1868 KB Output is correct
30 Correct 89 ms 1872 KB Output is correct