Submission #745872

# Submission time Handle Problem Language Result Execution time Memory
745872 2023-05-21T09:00:31 Z vjudge1 Kitchen (BOI19_kitchen) C++17
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define se second

void imp() {
    cout << "Impossible";
    cout << "\n";
    exit(0);
}

int n, m, k;
vector<int> a, b;
int sum_a;

int try_4(int idx) {
    int pref = 0;
    for(int i = 0; i <= idx; i++) {
        pref += b[i];
    }
    if(pref < sum_a) {
        return -1;
    }
    int sum1 = 0;
    for(int i = 0; i <= idx; i++) {
        sum1 += min(n, b[idx]);
    }
    if(sum1 < n * k) {
        return -1;
    }
    return pref - sum_a;
}

void solve() {
    cin >> n >> m >> k;
    a.resize(n), b.resize(m);
    for(int &x : a) {
        cin >> x;
        sum_a += x;
    }
    sort(a.begin(), a.end());
    for(int &x : b) {
        cin >> x;
    }
    sort(b.begin(), b.end());
    reverse(b.begin(), b.end());
    for(int i = 0; i < n; i++) {
        if(a[i] < k) {
            imp();
        }
    }
    int l = -1, r = m + 1;
    bool possible = false;
    int result = -3210;
    while(l < r - 1) {
        int mid = (l + r) / 2;
        int res = try_4(mid);
        if(res != -1 && (result == -3210 || result > res)) {
            result = res;
        }
        if(res != -1) {
            r = mid;
        } else {
            l = mid;
        }
    }
    if(r == m) {
        imp();
    }
    cout << result << "\n";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}

Compilation message

kitchen.cpp: In function 'void solve()':
kitchen.cpp:58:10: warning: unused variable 'possible' [-Wunused-variable]
   58 |     bool possible = false;
      |          ^~~~~~~~
# 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 Incorrect 1 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 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -