Submission #844232

# Submission time Handle Problem Language Result Execution time Memory
844232 2023-09-05T11:41:06 Z vjudge1 Pod starim krovovima (COCI20_psk) C++17
50 / 50
1 ms 596 KB
#pragma GCC optimize("unroll-loops,Ofast,O3")
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define spc << " " <<
#define all(x) x.begin(), x.end()
#define ll long long
#define int long long
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define st first
#define nd second
#define inf 1000000009
#define MOD 1000000007

using namespace std;




void solve(){
    int n; cin >> n;
    int tot=0;
    ii arr[n+1];
    for(int i=1; i<=n; i++){
        int a,b; cin >> a >> b;
        tot+=a;
        arr[i]={b, i};
    }
    sort(arr+1, arr+n+1, greater<ii>());
    int ans[n+1];
    memset(ans, 0, sizeof(ans));
    int ptr=1;
    while(tot>0 && ptr<=n){
        auto p=arr[ptr];
        ans[p.nd]=min(p.st, tot);
        tot-=p.st;
        ptr++;
    }
    cout << n-ptr+1 << endl;
    for(int i=1; i<=n; i++) cout << ans[i] << " ";
}



signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    #ifdef Local
    freopen("in","r",stdin);
    freopen("out","w",stdout);
    #endif
    

    ll 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 348 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 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 348 KB Output is correct
10 Correct 0 ms 596 KB Output is correct