Submission #567368

# Submission time Handle Problem Language Result Execution time Memory
567368 2022-05-23T11:05:37 Z birthdaycake Kitchen (BOI19_kitchen) C++17
20 / 100
16 ms 1048 KB
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define mod 1000000007
#define boost ios_base::sync_with_stdio(false), cin.tie(NULL);
using namespace std;
 
 
 
 
int dp[200001],a[20001],b[200001];
 
signed main(){
    boost;
    
    
    
    
    int n,m,k,sum = 0; cin >> n >> m >>  k;
    for(int i = 0; i < n; i++){
        cin >> a[i]; sum += a[i];
    }
    
    if(k == 1){
        for(int j = 0; j < m; j++) cin >> b[j];
        
        dp[0] = 1;
        for(int i = 0; i < m; i++){
            for(int j = 90000; j >= b[i]; j--){
                dp[j] += dp[j - b[i]];
            }
        }
        for(int i = sum; i <= 90000; i++){
            if(dp[i]){
                cout << i - sum;
                return 0;
            }
        }
        cout << "Impossible";
        return 0;
    }
    
    
    for(int j = 0; j < m; j++) cin >> b[j];
    
    if(m < k){
        cout << "Impossible";
        return 0;
    }
    
    for(int i = 0; i < n; i++){
        if(a[i] < k){
            cout << "Impossible";
            return 0;
        }
    }
    
    
    
    int ans = 1e18;
    for(int i = 0; i < (1 << m); i++){
        priority_queue<pair<int,int>>x; int tot = 0, good = 1;
        for(int j = 0; j < m; j++){
            if(i & (1 << j)){
                x.push({b[j],j});
                tot += b[j];
            }
        }
        for(int j = 0; j < n; j++){
            int cnt = 0;
            vector<pair<int,int>>d;
            while(!x.empty() && cnt < k){
                auto y = x.top();
                x.pop();
                if(y.first){
                    y.first--;
                    if(y.first) d.push_back(y);
                    cnt++;
                }else{
                    good = 0;
                }
            }
            if(cnt < k) good = 0;
            for(int f = 0; f < d.size(); f++){
                x.push(d[i]);
            }
        }
        if(good){
            if(tot >= sum) ans = min(ans,tot - sum);
        }
        
    }
    if(ans == 1e18){
        cout << "Impossible";
        return 0;
    }
    cout << ans;
    return 0;
}

Compilation message

kitchen.cpp: In function 'int main()':
kitchen.cpp:84:30: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |             for(int f = 0; f < d.size(); f++){
      |                            ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 2 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 2 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 980 KB Output is correct
2 Correct 11 ms 980 KB Output is correct
3 Correct 16 ms 1048 KB Output is correct
4 Correct 15 ms 980 KB Output is correct
5 Correct 15 ms 980 KB Output is correct
6 Correct 10 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 2 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -