Submission #440460

#TimeUsernameProblemLanguageResultExecution timeMemory
440460mashrur_hossainPod starim krovovima (COCI20_psk)C++14
50 / 50
1 ms348 KiB
#include <bits/stdc++.h> #define fast_cin ios_base::sync_with_stdio(0); cin.tie(NULL); cerr.tie(NULL); #define endl "\n" #define dbg(x) cerr << #x << ": " << x << endl; #define DBG cerr << __LINE__ << ": I GOT STUCK\n"; using namespace std; typedef long long ll; typedef long double db; void solve(){ ll n;cin >> n; ll tot = 0; vector<pair<ll, ll>>v; for(ll i = 0;i<n;i++){ ll t,z;cin >> t >> z; tot += t; v.emplace_back(z, i); } sort(v.rbegin(), v.rend()); vector<ll>ans(n, 0); for(ll i = 0;i<n;i++){ if(tot > v[i].first){ // fill it up ans[v[i].second] = v[i].first; tot -= v[i].first; } else{ // the rest are empty ans[v[i].second] = tot; break; } } ll cnt = 0; for(ll i = 0;i<n;i++){ if(ans[i] == 0)cnt++; } cout << cnt << endl; for(ll i = 0;i<n;i++){ cout << ans[i] << " \n"[i==n-1]; } } int main() { fast_cin; int test;test = 1; // int test;cin >>test; while(test--){ solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...