Submission #518418

#TimeUsernameProblemLanguageResultExecution timeMemory
518418PlurmCarnival Tickets (IOI20_tickets)C++17
0 / 100
18 ms2476 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; long long find_maximum(int k, vector<vector<int>> x) { int n = x.size(); int m = x[0].size(); vector<vector<int>> answer; for (int i = 0; i < n; i++) { vector<int> row(m); for (int j = 0; j < m; j++) { row[j] = -1; } answer.push_back(row); } long long ans = 0ll; int lo = 0; int hi = 1e9; int mid; while(lo < hi){ mid = (lo + hi)/2; int totcnt = 0; for(int i = 0; i < n; i++){ int icnt = upper_bound(x[i].begin(),x[i].end(),mid) - x[i].begin(); totcnt += icnt; } if(totcnt >= n*m/2){ hi = mid; }else{ lo = mid+1; } } int totcnt = 0; vector<int> negbar; for(int i = 0; i < n; i++){ int icnt = upper_bound(x[i].begin(),x[i].end(),mid) - x[i].begin(); if(totcnt + icnt > n*m/2){ icnt = n*m/2 - totcnt; } negbar.push_back(icnt); totcnt += icnt; } for(int t = 0; t < k; t++){ vector<int> idxs; for(int i = 0; i < n; i++) idxs.push_back(i); sort(idxs.begin(), idxs.end(), [&negbar](int x, int y){ return negbar[x] < negbar[y]; }); for(int i = 0; i < n/2; i++){ for(int j = m-1; j >= 0; j--){ if(answer[idxs[i]][j] == -1){ answer[idxs[i]][j] = t; ans -= x[idxs[i]][j]; break; } } } for(int i = n/2; i < n; i++){ negbar[idxs[i]]--; for(int j = 0; j < m; j++){ if(answer[idxs[i]][j] == -1){ answer[idxs[i]][j] = t; ans += x[idxs[i]][j]; break; } } } } allocate_tickets(answer); 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...