Submission #212061

#TimeUsernameProblemLanguageResultExecution timeMemory
212061NONAMEPod starim krovovima (COCI20_psk)C++17
50 / 50
6 ms384 KiB
#include <bits/stdc++.h> //#pragma GCC optimize("unroll-loops") //#pragma GCC optimize("-O3") //#pragma GCC optimize("Ofast") #define F first #define S second using namespace std; bool cmp(pair <pair <int, int>, int> x, pair <pair <int, int>, int> y) { if (x.F.S != y.F.S) return x.F.S > y.F.S; if (x.F.F != y.F.F) return x.F.F > y.F.F; return x.S < y.S; } int main() { //freopen("army.in","r",stdin); freopen("army.out","w",stdout); ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector <pair <pair <int, int>, int> > g; g.resize(n); for (int i = 0; i < n; i++) {g[i].S = i; cin >> g[i].F.F >> g[i].F.S;} sort(g.begin(), g.end(), cmp); int j = 1; for (int i = 0; i < n; i++) { while (j < n && g[j].F.F == 0) j++; if (i == j) j++; if (j == n) break; if (g[i].F.S - g[i].F.F > g[j].F.F) {g[i].F.F += g[j].F.F; g[j].F.F = 0; i--; j++; continue;} g[j].F.F -= g[i].F.S - g[i].F.F; g[i].F.F = g[i].F.S; } int ans = 0; int anser[n]; for (auto it : g) {if (it.F.F == 0) ans++; anser[it.S] = it.F.F;} cout << ans << endl; for (int i = 0; i < n; i++) cout << anser[i] << " "; }
#Verdict Execution timeMemoryGrader output
Fetching results...