Submission #567193

# Submission time Handle Problem Language Result Execution time Memory
567193 2022-05-23T09:03:24 Z Majid Kitchen (BOI19_kitchen) C++17
20 / 100
35 ms 1068 KB
#include<bits/stdc++.h>
using namespace std;
 
//Types
using ll = long long;
using db = double;
 
//Vectors
#define pb push_back
#define sz(vec) ((ll)vec.size())
#define all(vec) vec.begin(), vec.end()
 
//things
#define f first
#define s second
const int SMALLINF = 1e9 + 7;
const ll BIGINF = ((ll)1e18) + 7;
#define Speeed ios::sync_with_stdio(0);cin.tie(NULL); cout.tie(NULL);
ll t[90007];
void solve(){

    ll n, m, k, sum = 0, sum2 = 0;
    cin>>n>>m>>k;
    
    bool imp = false;
    
    if(m<k)imp = true;
    vector<ll> vec(n), hr(m);
    
    for(ll i = 0; i < n; i++){
        
        cin>>vec[i];
        sum+=vec[i];
        if(vec[i]<k)imp = true;
    }
    
    for(ll i = 0; i < m; i++){
        
        cin>>hr[i];
        sum2+=hr[i];
    }
    
    if(sum>sum2)imp = true;
    
    sort(all(hr));
    // 5 5 5 
    // 
    // 14 1
    
    if(m<=2){
        
        for(ll i = 0; i < m; i++){
            
            if(hr[i]<n)imp = true;
        }
        
        if(!imp)cout<<sum2 - sum;
        else cout<<"Impossible";
    }
    
    else{
    
    t[0] = 1;
    
    for(ll i = 0; i < m; i++){
        
        for(ll j = 90007; j>= hr[i]; j--){
            
            t[j] = (t[j] or t[j-hr[i]]);
        }
        
    }
    
    ll ans = -1;
    
    for(ll i = sum; i <= 90007; i++){
        
        if(t[i]!=0){
            
            ans = i;
            break;
        }
    }
    
    if(ans==-1 or imp)cout<<"Impossible";
    else cout<<ans - sum;
    
}


}


int main(){
	Speeed
	
    ll t=1;
    // cin>>t;
    
    while(t--){
        
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 31 ms 980 KB Output is correct
2 Correct 29 ms 1024 KB Output is correct
3 Correct 35 ms 1028 KB Output is correct
4 Correct 35 ms 980 KB Output is correct
5 Correct 32 ms 980 KB Output is correct
6 Correct 28 ms 1016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 1068 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -