Submission #400884

#TimeUsernameProblemLanguageResultExecution timeMemory
400884DavidDamianPod starim krovovima (COCI20_psk)C++11
50 / 50
2 ms208 KiB
#include <iostream> #include <algorithm> using namespace std; typedef long long ll; struct vaso { int vol; int agua; int id; }; bool porVolumen(vaso A, vaso B) { if (A.vol < B.vol) return true; else { if (A.vol == B.vol) { if (A.agua < B.agua) return true; else return false; } else return false; } } bool porId(vaso A, vaso B) { return A.id < B.id; } vaso A[100005]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> A[i].agua >> A[i].vol; A[i].id = i; } sort(A + 1, A + 1 + n, porVolumen); int j_max = n; while (j_max >= 1 && A[j_max].vol - A[j_max].agua == 0){ j_max--; } for (int i = 1; i <= n; i++) { if (i >= j_max) { break; } while (A[i].agua > 0){ int agua = min(A[j_max].vol - A[j_max].agua, A[i].agua); A[j_max].agua += agua; A[i].agua -= agua; if (A[j_max].vol - A[j_max].agua == 0) { j_max--; } if (i >= j_max) { break; } } } sort(A + 1, A + 1 + n, porId); int total = 0; for (int i = 1; i <= n; i++) { if (A[i].agua == 0) { total++; } } cout << total << endl; for (int i = 1; i <= n; i++) { cout << A[i].agua << " "; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...