Submission #938697

# Submission time Handle Problem Language Result Execution time Memory
938697 2024-03-05T12:46:59 Z vjudge1 Kitchen (BOI19_kitchen) C++17
31 / 100
1000 ms 600 KB
#include <bits/stdc++.h>
#define int long long 
#define endl "\n"
using namespace std;
vector<int>a;
vector<int>b;
vector<int>contribution;
int n,m,k;
int total=0;
int sum=0;
int c=0;
int c1;
int smallest=INT_MAX;
void dp(int i){
    if(i>=m)return;
    if(sum>smallest){
        return;
    }
    sum+=b[i];
    c+=contribution[i];
    if(c>=c1&&sum>=total){
        smallest=min(smallest,sum);
        if(sum==smallest){
            sum-=b[i];
            c-=contribution[i];
            return;
        }
    }
    dp(i+1);
    sum-=b[i];
    c-=contribution[i];
    dp(i+1);
}
signed main(){
    cin>>n>>m>>k;
    c1=n*k;
    a.resize(n);
    b.resize(m);
    contribution.resize(m);
    int cont=0;

    int s=0;
    bool flag=false;
    for(int i=0;i<n;i++){
        cin>>a[i];
        total+=a[i];
        if(a[i]<k){
            flag=true;
        }
    }
    for(int i=0;i<m;i++){
        cin>>b[i];
        s+=b[i];
        contribution[i]=min(n,b[i]);
        cont+=contribution[i];
    }
    if(flag){
        cout<<"Impossible\n";
        return 0;
    }
    if((n*k)>cont){
        cout<<"Impossible\n";
        return 0;
    }
    if(total>s){
        cout<<"Impossible\n";
        return 0;
    }
    dp(0);
    cout<<smallest-total<<endl;
}
# 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 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# 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 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 352 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1061 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1022 ms 344 KB Time limit exceeded
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 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 352 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Execution timed out 1061 ms 348 KB Time limit exceeded
15 Halted 0 ms 0 KB -