답안 #567140

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
567140 2022-05-23T08:24:11 Z birthdaycake Kitchen (BOI19_kitchen) C++17
0 / 100
1 ms 340 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 a[200001],b[200001],yes[200001];

signed main(){
    boost;
    
    
    
    
    int n,m,k, ans = 0,tot = 0, hours = 0; cin >> n >> m >> k;
    
    set<pair<int,int>>x;
    
    
    for(int i = 0; i < n; i++) cin >> a[i];
    
    
    for(int j = 0; j < m; j++){
        cin >> b[j];
        x.insert({b[j],j});
    }
    
    for(int i = 0; i < n; i++){
        vector<pair<int,int>>used;
        set<int>track;
        while(!x.empty() && track.size() < k && a[i] > 0){
            auto y = *x.begin();
            x.erase(x.begin());
            if(y.first){
                b[y.second]--;
                a[i]--;
                if(b[y.second]) used.push_back({b[y.second],y.second});
                track.insert(y.second);
                yes[y.second]++;
            }else{
                cout << "Impossible";
                return 0;
            }
        }
        if(track.size() < k){
            cout << "Impossible";
            return 0;
        }
        for(int j = 0; j < used.size(); j++) x.insert(used[j]);
        tot += a[i];
    }
    for(int i = 0; i < m; i++){
        if(yes[i]) ans += b[i];
    }
    if(ans - tot >= 0){
        cout << ans - tot;
        return 0;
    }
    priority_queue<int>y;
    for(int i = 0; i < m; i++){
        if(!yes[i]) y.push(-b[i]);
    }
    tot -= ans;
    ans = 0;
    while(y.size() && tot > 0){
        auto f = y.top();
        y.pop();
        if(-f >= tot){
            ans = -f - tot;
        }else{
            tot -= -f;
        }
    }
    if(tot){
        cout << "Impossible";
        return 0;
    }
    cout << ans;
    
    return 0;
}

Compilation message

kitchen.cpp: In function 'int main()':
kitchen.cpp:35:42: warning: comparison of integer expressions of different signedness: 'std::set<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   35 |         while(!x.empty() && track.size() < k && a[i] > 0){
      |                             ~~~~~~~~~~~~~^~~
kitchen.cpp:49:25: warning: comparison of integer expressions of different signedness: 'std::set<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   49 |         if(track.size() < k){
      |            ~~~~~~~~~~~~~^~~
kitchen.cpp:53:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         for(int j = 0; j < used.size(); j++) x.insert(used[j]);
      |                        ~~^~~~~~~~~~~~~
kitchen.cpp:19:33: warning: unused variable 'hours' [-Wunused-variable]
   19 |     int n,m,k, ans = 0,tot = 0, hours = 0; cin >> n >> m >> k;
      |                                 ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -