Submission #886397

#TimeUsernameProblemLanguageResultExecution timeMemory
886397NeroZeinCarnival Tickets (IOI20_tickets)C++17
100 / 100
543 ms76376 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; long long find_maximum(int k, vector<vector<int>> x) { int n = x.size(); int m = x[0].size(); long long ret = 0; priority_queue<pair<int, int>> pq; for (int i = 0; i < n; ++i) { for (int j = m - 1; j >= m - k; --j) { ret += x[i][j]; } pq.emplace(-x[i][0] - x[i][m - k], i); } int cnt = 0; vector<int> t(n); while (cnt < n * k / 2) { auto [val, ind] = pq.top(); pq.pop(); cnt++; ret += val; t[ind]++; if (t[ind] < k) { pq.emplace(-x[ind][t[ind]] - x[ind][m - k + t[ind]], ind); } } while (!pq.empty()) pq.pop(); vector<int> c(n), c2(n); for (int i = 0; i < n; ++i) { c2[i] = m - k + t[i]; } vector<vector<int>> answer(n, vector<int> (m, -1)); for (int round = 0; round < k; ++round) { vector<int> ord(n); iota(ord.begin(), ord.end(), 0); sort(ord.begin(), ord.end(), [&](int i, int j) { return t[i] - c[i] > t[j] - c[j]; }); for (int j = 0, taken = 0; j < (int) ord.size(); ++j) { if (taken < n / 2) { answer[ord[j]][c[ord[j]]] = round; c[ord[j]]++; taken++; } else { answer[ord[j]][c2[ord[j]]] = round; c2[ord[j]]++; } } } allocate_tickets(answer); 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...