Submission #868754

#TimeUsernameProblemLanguageResultExecution timeMemory
868754pccPod starim krovovima (COCI20_psk)C++14
50 / 50
1 ms464 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll,ll> #define pii pair<int,int> #define fs first #define sc second #define tlll tuple<ll,ll,ll> const ll mxn = 1010; pll arr[mxn]; ll ans[mxn]; int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); int n; cin>>n; ll sum = 0; priority_queue<pll,vector<pll>,less<pll>> pq; for(int i =1;i<=n;i++){ cin>>arr[i].fs>>arr[i].sc; pq.push({arr[i].sc,i}); sum += arr[i].fs; } while(sum>pq.top().fs){ ans[pq.top().sc] = pq.top().fs; sum -= pq.top().fs; pq.pop(); } ans[pq.top().sc] = sum; ll cnt = 0; for(int i = 1;i<=n;i++)if(!ans[i])cnt++; cout<<cnt<<'\n'; for(int i = 1;i<=n;i++)cout<<ans[i]<<' '; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...