Submission #567237

# Submission time Handle Problem Language Result Execution time Memory
567237 2022-05-23T09:38:53 Z katwamiaw Kitchen (BOI19_kitchen) C++14
9 / 100
3 ms 212 KB
#include<bits/stdc++.h>
#define ll long long
#define no cout << "NO\n"
#define yes cout << "YES\n"
#define endl '\n'
#define pb push_back
using namespace std ;
//fflush(stdout) ;

const int Max_n=305 ;
int a[Max_n] , b[Max_n] ;
int dp[Max_n*Max_n] ;
int n , m , k ;
int sum_a=0 , sum_b=0 ;

int work(){
    int ans=-1 ;
    sort(b,b+m) ;
    for(int i=1 ; i<(1<<m) ; i++){
        int r=0 , sum=0 ;
        for(int j=0 ; j<m ; j++){
            if(i&(1<<j)){
                r++ ;
                sum+=b[j] ;
            }
        }
        if(r<k||sum<sum_a) continue ;
        int re=0 , h=0 , x=0 ;
        for(int j=m ; j>=0 ; j--){
            if(h==k){
                x=1 ;
                break ;
            }
            if(!(i&(1<<j))) continue ;
            if(b[j]>=(n-re)){
                h++ ;
                re=0 ;
            }
            else{
                re+=b[j] ;
            }
        }
        if(h==k||x==1){
            if(ans==-1) ans=sum-sum_a ;
            ans=min(ans,sum-sum_a) ;
        }
    }
    return ans ;
}

int main(){
    cin >> n >> m >> k ;

    for(int i=0 ; i<n ; i++) cin >> a[i] ;
    for(int i=0 ; i<m ; i++) cin >> b[i] ;

    for(int i=0 ; i<n ; i++) sum_a+=a[i] ;
    for(int i=0 ; i<m ; i++) sum_b+=b[i] ;

    for(int i=0 ; i<n ; i++){
        if(a[i]<k){
            cout << "Impossible" ;
            return 0 ;
        }
    }

    if(sum_a>sum_b){
        cout << "Impossible" ;
        return 0 ;
    }

    if(m<=2){

        if(k>m){
            cout << "Impossible" ;
            return 0 ;
        }
        if(k==m){

            for(int i=0 ; i<m ; i++){
                if(b[i]<n){
                    cout << "Impossible" ;
                    return 0 ;
                }
            }
            cout << sum_b-sum_a ;
        }
        else{
            int ans=400 ;
            if(b[0]>=sum_a) ans=b[0]-sum_a ;
            if(b[1]>=sum_a) ans=min(b[1]-sum_a,ans) ;

            if(ans==400){
                if(sum_a>sum_b){
                    cout << "Impossible" ;
                    return 0 ;
                }
                cout << sum_b-sum_a ;
            }
            else cout << ans ;
        }
        return 0 ;
    }
    int ans=work() ;
    if(ans==-1) cout << "Impossible" ;
    else cout << ans ;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 3 ms 212 KB Output is correct
11 Correct 3 ms 212 KB Output is correct
12 Correct 3 ms 212 KB Output is correct
13 Incorrect 3 ms 212 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 3 ms 212 KB Output is correct
11 Correct 3 ms 212 KB Output is correct
12 Correct 3 ms 212 KB Output is correct
13 Incorrect 3 ms 212 KB Output isn't correct
14 Halted 0 ms 0 KB -