Submission #1004692

#TimeUsernameProblemLanguageResultExecution timeMemory
1004692phoenixCarnival Tickets (IOI20_tickets)C++17
100 / 100
594 ms116476 KiB
#include "tickets.h" #include <vector> #include <bits/stdc++.h> using namespace std; using ll = long long; long long find_maximum(int k, vector<vector<int>> x) { int n = x.size(), m = x[0].size(); long long S = 0; vector<vector<int>> answer(n, vector<int>(m, -1)); vector<int> l(n, -1), r(n, m); priority_queue<pair<ll, int>> pq; for (int i = 0; i < n; i++) { for (int j = 0; j < k; j++) { S -= x[i][++l[i]]; pq.push({x[i][j] + x[i][m - k + j], i}); } } for (int iter = 0; iter < (n / 2) * k; iter++) { int i = pq.top().second; pq.pop(); S += x[i][--r[i]]; S += x[i][l[i]--]; } for (int iter = 0; iter < k; iter++) { int cnt = 0; for (int i = 0; i < n; i++) { if (r[i] == m) { answer[i][l[i]--] = iter; cnt++; } } assert(cnt <= n / 2); for (int i = 0; i < n; i++) { if (r[i] == m) continue; if (cnt < n / 2 && l[i] >= 0) { answer[i][l[i]--] = iter; cnt++; } else { answer[i][r[i]++] = iter; } } } allocate_tickets(answer); return S; }
#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...