Submission #82886

#TimeUsernameProblemLanguageResultExecution timeMemory
82886MilkiHokej (COCI17_hokej)C++14
120 / 120
171 ms6908 KiB
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for(int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define _ << " " << #define sz(x) (int)x.size() #define pb(x) push_back(x) typedef long long ll; typedef pair<int, int> point; struct igrac{ int k = 0, i = 0, id = 0; igrac(int _k, int _i, int _id){ k = _k; i = _i; id = _id; } friend bool operator < (const igrac A, const igrac B){ return A.k > B.k; } }; vector <igrac> v, zamjene; vector <int> postava[6]; int n, m; int tijme[6], start[6], bio[6]; bool cmp(igrac A, igrac B){ return A.k < B.k; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m; REP(i, m){ int a, b; cin >> a >> b; v.pb(igrac(a, b, i + 1)); } sort(v.begin(), v.end()); ll sol = 0; int l = 0, r = 5; for(auto &it : v){ if(l > r) break; if(it.i >= n && l != r){ sol += (ll)n * it.k; postava[r].pb(it.id); r --; } else{ int left = n - tijme[l]; if(it.i >= left){ sol += (ll)left * it.k; if(!postava[l].empty()) zamjene.pb(igrac(tijme[l], postava[l].back(), it.id)); postava[l].pb(it.id); l ++; if(l > r) break; it.i -= left; if(it.i == 0) continue; tijme[l] += it.i; sol += (ll)it.i * it.k; postava[l].pb(it.id); } else{ sol += (ll)it.i * it.k; if(!postava[l].empty()) zamjene.pb(igrac(tijme[l], postava[l].back(), it.id)); postava[l].pb(it.id); tijme[l] += it.i; } } } sort(zamjene.begin(), zamjene.end(), cmp); cout << sol << "\n"; REP(i, 6) cout << postava[i][0] << " "; cout << "\n"; cout << sz(zamjene) << "\n"; for(auto it : zamjene){ cout << it.k _ it.i _ it.id << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...