Submission #731444

# Submission time Handle Problem Language Result Execution time Memory
731444 2023-04-27T12:44:37 Z vjudge1 Pod starim krovovima (COCI20_psk) C++17
50 / 50
1 ms 340 KB
#include <iostream>
#include <algorithm>
#define int long long
using namespace std;
bool sorter(pair<int, int> a, pair<int, int> b)
{
    return a.second > b.second;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    pair<int, int> a[n];
    int val[n];
    int t = 0;
    for (int i = 0; i < n; ++i)
    {
        a[i].first = i;
        int x;
        cin >> x;
        t += x;
        cin >> a[i].second;
        val[i] = 0;
    }
    sort(a, a + n, sorter);
    int ans = n;
    for (int i = 0; i < n; ++i)
    {
        if (t <= 0)
            break;
        int diff = min(t, a[i].second);
        t -= diff;
        ans--;
        val[a[i].first] = diff;
    }
    cout << ans << endl;
    for (int i = 0; i < n; ++i)
    {
        cout << val[i] << " ";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct