# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
657968 | mychecksedad | Carnival Tickets (IOI20_tickets) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define all(x) x.begin(), x.end()
void allocate_tickets(vector<vector<int>> _x);
long long find_maximum(int k, vector<vector<int>> _arr) {
int N = _arr.size(), M = _arr[0].size();
vector<vector<int>> answer;
vector<vector<pair<int,int>>> arr(N);
for (int i = 0; i < N; i++) {
std::vector<int> row(M, -1);
answer.push_back(row);
for(int j = 0; j < m; ++j) arr[i].pb({_arr[i][j], j});
}
vector<vector<pair<int,int>>> unused(N), small(N);
ll ans = 0;
for(int i = 0; i < N; ++i){
for(int j = 0; j < k; ++j) small[i].pb(arr[i][j]);
for(int j = 0; j < M; ++j) unused[i].pb(arr[i][j]);
}
for(int i = 0; i < k; ++i){
priority_queue<pair<int, int>> q;
for(int j = 0; j < N; ++j){
while(answer[j][unused[j].back().second] != -1) unused[j].pop_back();
q.push({unused[j].back().first + small[j].back().first, j});
}
for(int j = 0; j < N; ++j){
int v = q.top().second;
q.pop();
if(j < N/2){
ans += unused[v].back().first;
answer[v][unused[v].back().second] = i;
unused[v].pop_back();
}else{
ans -= small[v].back().first;
answer[v][small[v].back().second - 1] = i;
}
small[v].pop_back();
}
}
allocate_tickets(answer);
return ans;
}