Submission #440508

#TimeUsernameProblemLanguageResultExecution timeMemory
440508MahfuzAhmedPod starim krovovima (COCI20_psk)C++14
50 / 50
1 ms332 KiB
/** * author: mahfuzz * created: 02.07.2021 **/ #include <bits/stdc++.h> using namespace std; #define debug(x) cout << '>' << #x << ':' << x << endl; #define all(p) p.begin(),p.end() typedef long long ll; bool cmp(pair<ll, ll> a, pair<ll, ll> b){ if(a.first > b.first) return true; return false; } int main(int argc, char* argv[]){ ios_base::sync_with_stdio(0); cin.tie(nullptr); int n; cin >> n; vector<pair<ll, ll>> vec; ll sum = 0, arr[n]; for(int i = 0; i < n; i++){ ll x; cin >> x >> arr[i]; sum += x; vec.push_back({arr[i], 0}); } sort(all(vec), cmp); int cnt = 0; for(int i = 0; i < n; i++){ vec[i].second = min(sum, vec[i].first); sum -= vec[i].second; if(vec[i].second == 0) ++cnt; } cout << cnt << "\n"; for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ if(vec[j].first == arr[i]){ vec[j].first = -1; cout << vec[j].second << " "; break; } } } cout << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...