Submission #1283265

#TimeUsernameProblemLanguageResultExecution timeMemory
1283265MasterMoonPod starim krovovima (COCI20_psk)C++17
50 / 50
2 ms580 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define __Master_Moon__ int main() struct hung { ll x,y,id; }; bool cmp(hung a,hung b) { return a.y > b.y; } bool cmz(hung a,hung b) { return a.id < b.id; } void solve() { int n,ans = 0; cin >> n; hung a[n]; for(int i = 0;i < n;i++) { cin >> a[i].x >> a[i].y; a[i].id = i; } sort(a,a+n,cmp); for(int i = 0;i< n;i++) { for(int j = i + 1;j < n;j++) { if(a[i].x == a[i].y) break; if(a[i].x + a[j].x <= a[i].y) { a[i].x+=a[j].x; a[j].x = 0; } else { a[j].x-= (a[i].y-a[i].x); a[i].x=a[i].y; break; } } if(a[i].x == 0) ans++; } sort(a,a+n,cmz); cout << ans << endl; for(int i = 0;i < n;i++) cout << a[i].x << " "; } __Master_Moon__ { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("o.inp","r",stdin); // freopen("o.out","w",stdout); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...