답안 #567190

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
567190 2022-05-23T09:01:27 Z Majid Kitchen (BOI19_kitchen) C++17
20 / 100
41 ms 1032 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){
        
        if(hr[0]<n or hr[1]<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();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 1016 KB Output is correct
2 Correct 27 ms 1032 KB Output is correct
3 Correct 35 ms 980 KB Output is correct
4 Correct 41 ms 980 KB Output is correct
5 Correct 37 ms 1016 KB Output is correct
6 Correct 38 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 980 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -