Submission #844329

#TimeUsernameProblemLanguageResultExecution timeMemory
844329vjudge1Pod starim krovovima (COCI20_psk)C++14
50 / 50
1 ms348 KiB
#include <bits/stdc++.h> #define int long long using namespace std; template<typename T1, typename T2> ostream& operator<<(ostream& os, pair<T1, T2> p){ return os << p.first << " " << p.second; } void solve(void){ int x; cin >> x; vector<pair<int, int>> a(x); vector<int> dolu(x), son(x,0); int sum = 0; for(int i=0; i<x; i++){ cin >> dolu[i]; sum += dolu[i]; cin >> a[i].first; a[i].second = i; } sort(a.begin(), a.end(), [](pair<int,int> a, pair<int,int> b){ return a.first > b.first; } ); int ans = 0; for(int i=0; i<x; i++){ if(a[i].first < sum){ sum -= a[i].first; son[a[i].second] = a[i].first; }else{ son[a[i].second] = sum; sum -= sum; ans += !son[a[i].second]; } } cout << ans << "\n"; for(auto gh: son) cout << gh << " "; cout << "\n"; } signed main(){ int t=1; // cin >> t; while(t--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...