Submission #1057125

#TimeUsernameProblemLanguageResultExecution timeMemory
1057125aufanCarnival Tickets (IOI20_tickets)C++17
100 / 100
401 ms63260 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; long long find_maximum(int k, vector<vector<int>> a) { int n = (int)a.size(), m = (int)a[0].size(); long long res = 0; vector<vector<int>> bad(n, vector<int>(m)); for (int i = 0; i < n; i++) { for (int j = 0; j < k; j++) { res -= a[i][j]; } } priority_queue<array<int, 3>> pq; for (int i = 0; i < n; i++) { pq.push({a[i][m - 1] + a[i][k - 1], i, 0}); } vector<int> cnt(n, k); for (int i = 0; i < n * k / 2; i++) { auto [x, j, d] = pq.top(); pq.pop(); res += x; cnt[j] -= 1; if (d + 1 <= k - 1) pq.push({a[j][m - 1 - (d + 1)] + a[j][k - 1 - (d + 1)], j, d + 1}); } vector<int> pl(n, 0), pr(n, m - 1); vector<vector<int>> ans(n, vector<int>(m, -1)); for (int i = 0; i < k; i++) { vector<int> ord(n); iota(ord.begin(), ord.end(), 0); sort(ord.begin(), ord.end(), [&](int x, int y) { return cnt[x] > cnt[y]; }); for (int j = 0; j < n / 2; j++) { ans[ord[j]][pl[ord[j]]++] = i; cnt[ord[j]] -= 1; } for (int j = n / 2; j < n; j++) { ans[ord[j]][pr[ord[j]]--] = i; } } allocate_tickets(ans); return res; }
#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...