Submission #387479

#TimeUsernameProblemLanguageResultExecution timeMemory
387479WLZCarnival Tickets (IOI20_tickets)C++14
100 / 100
841 ms76396 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); priority_queue< pair<int, int> > pq; for (int i = 0; i < n; i++) { for (int j = 0; j < k; j++) ans -= x[i][j]; pq.push({x[i][ptr1[i]] + x[i][ptr2[i] - 1], i}); } for (int i = 0; i < k * n / 2; i++) { ans += pq.top().first; int idx = pq.top().second; pq.pop(); ptr1[idx]--; ptr2[idx]--; if (ptr1[idx] >= 0) pq.push({x[idx][ptr1[idx]] + x[idx][ptr2[idx] - 1], idx}); } vector< vector<int> > s(n, vector<int>(m, -1)); vector<int> v(n); iota(v.begin(), v.end(), 0); for (int i = 0; i < k; i++) { sort(v.begin(), v.end(), [&](int a, int b) { return ptr1[a] > ptr1[b]; }); for (int j = 0; j < n / 2; j++) { s[v[j]][ptr1[v[j]]--] = i; } for (int j = n / 2; j < n; j++) { s[v[j]][ptr2[v[j]]++] = i; } } 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...