Submission #899193

# Submission time Handle Problem Language Result Execution time Memory
899193 2024-01-05T15:13:34 Z Blagoj Pod starim krovovima (COCI20_psk) C++17
50 / 50
1 ms 468 KB
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define ll long long
#define all(x) (x).begin(), (x).end()

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<pair<ll, ll>> a(n);
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        ll x;
        cin >> x >> a[i].first;
        a[i].second = i;
        sum += x;
    }
    sort(all(a));
    reverse(all(a));
    ll left = n;
    ll ans[n];
    memset(ans, 0, sizeof(ans));
    for (int i = 0; i < n; i++) {
        left--;
        ans[a[i].second] = min(a[i].first, sum);
        sum -= a[i].first;
        if (sum <= 0) break;
    }
    cout << left << endl;
    for (int i = 0; i < n; i++) cout << ans[i] << " ";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 348 KB Output is correct