Submission #346354

#TimeUsernameProblemLanguageResultExecution timeMemory
346354dennisstarCarnival Tickets (IOI20_tickets)C++17
100 / 100
943 ms76268 KiB
#include <bits/stdc++.h> #include "tickets.h" using namespace std; using ll = long long; ll find_maximum(int K, vector<vector<int>> X) { int N = X.size(), M=X[0].size(); ll R=0; vector<int> T(N), l(N), r(N); priority_queue<pair<int, int>> pq; for (int i=0; i<N; i++) { pq.emplace(X[i][M-1]+X[i][K-1], i); for (int j=0; j<K; j++) R-=X[i][j]; } for (int i=0; i<K*N/2; i++) { int j=pq.top().second; R+=pq.top().first; pq.pop(); T[j]++; if (T[j]<K) pq.emplace(X[j][M-1-T[j]]+X[j][K-1-T[j]], j); } vector<vector<int>> A; while (pq.size()) pq.pop(); for (int i=0; i<N; i++) A.emplace_back(vector<int>(M, -1)), pq.emplace(T[i], i); for (int i=0; i<K; i++) { vector<int> chk(N); for (int j=0; j<N/2; j++) chk[pq.top().second]=1, pq.pop(); for (int j=0; j<N; j++) { if (chk[j]) { l[j]++; A[j][M-l[j]]=i; pq.emplace(T[j]-l[j], j); } else A[j][r[j]]=i, r[j]++; } } allocate_tickets(A); return R; }
#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...