Submission #635138

#TimeUsernameProblemLanguageResultExecution timeMemory
635138stevancvCarnival Tickets (IOI20_tickets)C++14
100 / 100
637 ms54340 KiB
#include <bits/stdc++.h> #include "tickets.h" #define ll long long #define ld long double #define sp ' ' #define en '\n' #define smin(a, b) a = min(a, b) #define smax(a, b) a = max(a, b) using namespace std; const int N = 5e5 + 2; const int mod = 1e9 + 7; ll find_maximum(int k, vector<vector<int>> a) { int n = a.size(); int m = a[0].size(); vector<int> l(n, k - 1), r(n, m - 1); priority_queue<array<int, 2>> pq; for (int i = 0; i < n; i++) pq.push({a[i][l[i]] + a[i][r[i]], i}); int uk = n * k / 2; while (uk--) { int i = pq.top()[1]; pq.pop(); l[i]--; r[i]--; if (l[i] >= 0) pq.push({a[i][l[i]] + a[i][r[i]], i}); } vector<int> kol(n); ll sol = 0; for (int i = 0; i < n; i++) { for (int j = 0; j <= l[i]; j++) sol -= a[i][j]; for (int j = r[i] + 1; j < m; j++) sol += a[i][j]; kol[i] = k - l[i] - 1; l[i] = 0; r[i] = m - 1; } vector<vector<int>> ans(n, vector<int>(m, -1)); for (int z = 0; z < k; z++) { vector<int> id(n); iota(id.begin(), id.end(), 0); sort(id.begin(), id.end(), [&] (int i, int j) { return kol[i] < kol[j]; }); for (int i = 0; i < n / 2; i++) { ans[id[i]][l[id[i]]] = z; l[id[i]]++; } for (int i = n / 2; i < n; i++) { ans[id[i]][r[id[i]]] = z; r[id[i]]--; kol[id[i]]--; } } allocate_tickets(ans); return sol; }
#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...