Submission #234502

#TimeUsernameProblemLanguageResultExecution timeMemory
234502VimmerHokej (COCI17_hokej)C++14
0 / 120
666 ms65544 KiB
#include <bits/stdc++.h> //#pragma GCC optimize("unroll-loops") //#pragma GCC optimize("-O3") //#pragma GCC optimize("Ofast") #define F first #define S second #define sz(x) int(x.size()) #define pb push_back #define N 500005 #define M ll(1e9 + 7) #define inf 1e9 + 1e9 using namespace std; typedef long double ld; typedef long long ll; typedef short int si; bool cmp(pair <pair <int, int>, int> x, pair <pair <int, int>, int> y) { if (x.F.F != y.F.F) return x.F.F > y.F.F; return x.F.S > y.F.S; } set <int> gt[N]; int main() { // freopen("input.txt", "r", stdin);// freopen("output.txt", "w", stdout); ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> m >> n; int obr[n], sum = 0; vector <pair <pair <int, int>, int> > g; g.resize(n); for (int i = 0; i < n; i++) {cin >> g[i].F.F >> g[i].F.S; g[i].S = i; sum += g[i].F.S;} vector <pair <int, pair <int, int> > > vr; vr.clear(); sort(g.begin(), g.end(), cmp); for (int i = 0; i < n; i++) obr[g[i].S] = i; int a[6]; set <int> st; st.clear(); set <pair <int, int> > se; se.clear(); for (int i = 0; i < 6; i++) {a[i] = g[i].S; se.insert({g[i].F.S, g[i].S}); st.insert(g[i].S);} int j = 6, pos = 0; vector <pair <int, int> > gr; gr.clear(); vector <pair <int, int> > ost; ost.clear(); vector <int> can; can.clear(); for (int i = 1; i <= m; i++) { for (auto it : st) {cout << it << " "; gt[it].insert(i);} cout << endl; if (i == m) break; vector <int> gr; gr.clear(); while (sz(se) > 0 && (*se.begin()).F == i) { gr.pb((*se.begin()).S); if (sz(can) != 6) can.pb(gr.back()); se.erase(se.begin()); st.erase(gr.back()); } int ut = 0, utr = 0; while (sz(gr) > 0 && j < sz(g)) { if (ut < sz(can) && pos + utr < sz(ost)) { int nmr = can[ut]; int tm = *gt[nmr].begin(); if (gt[nmr].find(tm) != gt[nmr].end()) {pos++; continue;} ost[pos + utr].F--; st.insert(nmr); se.insert({i + 1, nmr}); gr.pop_back(); gt[ost[pos + utr].S].insert(tm); gt[nmr].erase(tm); if (ost[pos + utr].F == 0) {pos++; utr--;} ut++; utr++; continue; } se.insert({i + g[j].F.S, g[j].S}); st.insert(g[j].S); int ostr = max(0, (i + g[j].F.S) - m); if (ostr > 0) ost.pb({ostr, g[j].S}); gr.pop_back(); j++; } } ll ans = 0; vector <int> tmr[m + 1]; for (int i = 0; i <= m; i++) tmr[i].clear(); for (int i = 0; i < n; i++) for (auto it : gt[i]) {tmr[it].pb(i); ans += g[obr[i]].F.F;} cout << ans << endl; for (int i = 0; i < 6; i++) a[i] = tmr[1][i]; sort(a, a + 6); vector <int> pr; pr.clear(); for (int i = 0; i < 6; i++) {pr.pb(a[i]); cout << a[i] + 1 << " "; } cout << endl; for (int i = 2; i <= m; i++) { sort(pr.begin(), pr.end()); vector <int> grr = tmr[i]; sort(grr.begin(), grr.end()); vector <int> nw; nw.clear(); int j = 0; while (j < sz(pr)) { if (pr[j] == grr[j]) nw.pb(pr[j]); else { nw.pb(grr[j]); vr.pb({i, {pr[j], grr[j]}}); } j++; } pr = nw; } cout << sz(vr) << endl; for (auto it : vr) cout << it.F << " " << it.S.F + 1 << " " << it.S.S + 1 << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...