Submission #387477

#TimeUsernameProblemLanguageResultExecution timeMemory
387477WLZCarnival Tickets (IOI20_tickets)C++14
76 / 100
3060 ms178284 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; long long find_maximum(int k, vector< vector<int> > x) { int n = (int) x.size(), m = (int) x[0].size(); long long ans = 0; vector<int> ptr1(n, k - 1), ptr2(n, m - 1); vector< vector< pair<int, int> > > sorted(n); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) sorted[i].push_back({x[i][j], j}); priority_queue< pair<int, int> > pq; vector< set<int> > plus(n), minus(n); for (int i = 0; i < n; i++) { sort(sorted[i].begin(), sorted[i].end()); for (int j = 0; j < k; j++) ans -= sorted[i][j].first, minus[i].insert(sorted[i][j].second); pq.push({sorted[i][ptr1[i]].first + sorted[i][ptr2[i]].first, i}); } for (int i = 0; i < k * n / 2; i++) { ans += pq.top().first; int idx = pq.top().second; pq.pop(); minus[idx].erase(sorted[idx][ptr1[idx]].second); plus[idx].insert(sorted[idx][ptr2[idx]].second); ptr1[idx]--; ptr2[idx]--; if (ptr1[idx] >= 0) pq.push({sorted[idx][ptr1[idx]].first + sorted[idx][ptr2[idx]].first, idx}); } vector< vector<int> > s(n, vector<int>(m, -1)); for (int i = 0; i < k; i++) { vector<int> v(n); iota(v.begin(), v.end(), 0); sort(v.begin(), v.end(), [&](int a, int b) { return (int) plus[a].size() > (int) plus[b].size(); }); for (int j = 0; j < n / 2; j++) { s[v[j]][*plus[v[j]].begin()] = i; plus[v[j]].erase(plus[v[j]].begin()); } for (int j = n / 2; j < n; j++) { s[v[j]][*minus[v[j]].begin()] = i; minus[v[j]].erase(minus[v[j]].begin()); } } allocate_tickets(s); return ans; }
#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...