Submission #844231

# Submission time Handle Problem Language Result Execution time Memory
844231 2023-09-05T11:40:45 Z vjudge1 Pod starim krovovima (COCI20_psk) C++17
50 / 50
1 ms 348 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6+37;
#define int long long


signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n; cin >> n;
    vector<int> a(n), ind(n), ans(n);
    iota(ind.begin(), ind.end(), 0);
    int sum=0;

    for (int i=0; i<n; i++){
       int x; cin >> x; sum+=x;

       cin >> a[i];
    }

    sort(ind.begin(), ind.end(), [&](int i, int j){
        return a[i] > a[j];
    });

    int s=0;
    for(int i=0; i<n; i++){
        int v=min(sum, a[ind[i]]);
        if(v==0) s++;
        ans[ind[i]]=v;
        sum-=v;
    }

    cout<<s<<"\n";

   for(auto i: ans) cout<<i<<" ";
} 
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 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 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct