Submission #844379

# Submission time Handle Problem Language Result Execution time Memory
844379 2023-09-05T12:49:19 Z vjudge1 Pod starim krovovima (COCI20_psk) C++17
50 / 50
1 ms 348 KB
#include <iostream>
#include <algorithm>
#include <utility>
using namespace std;

int main(){
    int64_t n, liq, *ans, index, ocount, total;
    pair<int64_t, int64_t> *glasses;
    cin >> n;
    glasses = new pair<int64_t, int64_t>[n];
    total = 0;
    for (int i = 0; i < n; i++){
        cin >> liq;
        total += liq;
        cin >> glasses[i].first;
        glasses[i].second = i;
    }
    std::sort(glasses, glasses + n);
    ans = new int64_t[n];
    for (int i = 0; i < n; i++) ans[i] = 0;
    index = n - 1;
    ocount = n;
    while (total > 0){
        ocount--;
        if (glasses[index].first > total){
            ans[glasses[index].second] = total;
            total = 0;
            break;
        }
        ans[glasses[index].second] = glasses[index].first;
        total -= glasses[index].first;
        index--;
    }
    cout << ocount << endl;
    for (int i = 0; i < n; i++){
        cout << ans[i];
        if (i != n - 1) cout << " ";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct