Submission #550252

#TimeUsernameProblemLanguageResultExecution timeMemory
550252jesus_coconutCarnival Tickets (IOI20_tickets)C++17
27 / 100
694 ms62924 KiB
#include "tickets.h" #include <bits/stdc++.h> #define all(a) begin(a), end(a) #define F first #define S second using namespace std; using ll = long long; vector<vector<int>> tickets; vector<pair<int, int>> points; long long find_maximum(int k, std::vector<std::vector<int>> x) { int n = size(x); int m = size(x[0]); ll ret = 0; tickets.resize(n, vector<int>(m, -1)); points.resize(n, {0, m - 1}); vector<vector<int>> sxidx(n, vector<int>(m)); for (int i = 0; i < n; ++i) { iota(all(sxidx[i]), 0); sort(all(sxidx[i]), [&](int a, int b) { return x[i][a] > x[i][b]; }); } vector<int> idx(n); iota(all(idx), 0); for (int i = 0; i < k; ++i) { sort(all(idx), [&](int a, int b) { return x[a][sxidx[a][points[a].S]] > x[b][sxidx[b][points[b].S]]; }); ll mx = -1; int mxid = -1; int need = n / 2; for (int j = 0; j < n; ++j) { ll cur = 0; need = n / 2; priority_queue<int> pq; for (int l = 0; l < n; ++l) { if (x[idx[l]][sxidx[idx[l]][points[idx[l]].S]] > x[idx[j]][sxidx[idx[j]][sxidx[idx[j]][points[idx[j]].S]]]) { cur += x[idx[l]][sxidx[idx[l]][points[idx[l]].F]]; need--; } else if (x[idx[l]][sxidx[idx[l]][points[idx[l]].F]] < x[idx[j]][sxidx[idx[j]][points[idx[j]].S]]) { cur -= x[idx[l]][sxidx[idx[l]][points[idx[l]].S]]; } else { cur -= x[idx[l]][sxidx[idx[l]][points[idx[l]].S]]; pq.push(x[idx[l]][sxidx[idx[l]][points[idx[l]].F]] + x[idx[l]][sxidx[idx[l]][points[idx[l]].S]]); } } if (need < 0) continue; while (need != 0 && !pq.empty()) { cur += pq.top(); pq.pop(); need--; } if (need != 0) continue; if (cur > mx) { mx = cur; mxid = j; } } ret += mx; need = n / 2; priority_queue<pair<int, int>> pq; for (int l = 0; l < n; ++l) { if (x[idx[l]][sxidx[idx[l]][points[idx[l]].S]] > x[idx[mxid]][sxidx[idx[mxid]][points[idx[mxid]].S]]) { tickets[idx[l]][sxidx[idx[l]][points[idx[l]].F]] = i; points[idx[l]].F++; need--; } else if (x[idx[l]][sxidx[idx[l]][points[idx[l]].F]] < x[idx[mxid]][sxidx[idx[mxid]][points[idx[mxid]].S]]) { tickets[idx[l]][sxidx[idx[l]][points[idx[l]].S]] = i; points[idx[l]].S--; } else { pq.push({x[idx[l]][sxidx[idx[l]][points[idx[l]].F]] + x[idx[l]][sxidx[idx[l]][points[idx[l]].S]], l}); } } while (need != 0) { auto [v, l] = pq.top(); pq.pop(); tickets[idx[l]][sxidx[idx[l]][points[idx[l]].F]] = i; points[idx[l]].F++; need--; } while (!pq.empty()) { auto [v, l] = pq.top(); pq.pop(); tickets[idx[l]][sxidx[idx[l]][points[idx[l]].S]] = i; points[idx[l]].S--; } } allocate_tickets(tickets); return ret; }
#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...