Submission #603978

#TimeUsernameProblemLanguageResultExecution timeMemory
603978lcjCarnival Tickets (IOI20_tickets)C++17
11 / 100
2 ms724 KiB
#include <bits/stdc++.h> #define fi first #define se second using namespace std; typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pii; #include "tickets.h" ll find_maximum(int k, vector<vector<int>> x) { int n = x.size(); int m = x[0].size(); vector<int> lidx(n, 0), hidx(n, m-1); ll su = 0; vector<vector<int>> ans(n, vector<int>(m, -1)); for (int cur = 0; cur < k; cur++) { multiset<pii> active; for (int i = 0; i < n; i++) { active.insert({x[i][lidx[i]], i}); if (lidx[i] != hidx[i]) { active.insert({x[i][hidx[i]], i}); } } for (int i = 0; i < n/2; i++) { auto lo = active.begin();auto hi = --active.end(); multiset<pii>::iterator c1, c2; c1 = lo;c2 = hi; if (lo->se != hi->se) { c1 = lo;c2 = hi; } else { auto c11 = c1; auto c22 = c2; ++c1; --c2; if (c2->se - c11->se > c22->se - c1->se) { c1 = c11; } else { c2 = c22; } } su += c2->fi-c1->fi; ans[c1->se][lidx[c1->se]] = cur; ans[c2->se][hidx[c2->se]] = cur; int col1 = c1->se; int col2 = c2->se; active.erase(c1); active.erase(c2); if (lidx[col1] != hidx[col1]) { active.erase(active.find({x[col1][hidx[col1]], col1})); } if (lidx[col2] != hidx[col2]) { active.erase(active.find({x[col2][lidx[col2]], col2})); } lidx[col1]++; hidx[col2]--; } } allocate_tickets(ans); return su; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...