Submission #844229

# Submission time Handle Problem Language Result Execution time Memory
844229 2023-09-05T11:40:02 Z vjudge1 Pod starim krovovima (COCI20_psk) C++17
50 / 50
1 ms 348 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
#define int long long

#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    #define OPEN freopen(".in", "r", stdin); \
                 freopen(".out", "w", stdout);
#else
    #define OPEN void(23);
#endif

void solve()
{
    int n; cin >> n;
    array <int, 3> arr[n];
    int sum = 0, cnt = 0;
    for(auto &[a, b, c] : arr) cin >> a >> b, sum += a, c = cnt++;

    sort(arr, arr + n, [&](array <int, 3> &a, array <int, 3> &b)
    {
        return a[1] > b[1];
    });

    vector <int> ans(n);
    int cev = n;
    for(int i = 1; i <= n; i++)
    {
        if(sum <= arr[i -1][1])
        {
            ans[arr[i -1][2]] = sum;
            cev--;
            break;
        }

        ans[arr[i -1][2]] = arr[i -1][1];
        sum -= arr[i -1][1];
        cev--;
    }

    cout << cev << "\n";
    for(int &i : ans) cout << i << " ";

    return;
}

int32_t main()
{
    OPEN;

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int t = 1; //cin >> t;
    while(t--)
    {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 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 0 ms 348 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 344 KB Output is correct