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"
#include "tickets.h"
using namespace std;
#define int long long
long long find_maximum(int32_t k,vector<vector<int32_t>> x){
int n = x.size();
int m = x[0].size();
vector<vector<int32_t>> vis(n,vector<int32_t>(m,-1));
vector<vector<int32_t>> VIS(n,vector<int32_t>(m,-1));
long long fin = 0;
priority_queue<array<int,4>> pq;
for(int i = 0;i<n;i++){
vector<pair<int,int>> v;
for(int j = 0;j<m;j++){
v.push_back({x[i][j],j});
}
sort(v.begin(),v.end());
reverse(v.begin(),v.end());
for(int j = 0;j<k;j++){
fin+=v[j].first;
VIS[i][v[j].second] = 1;
int lol = m-1-(k-1-j);
pq.push({-v[j].first-v[lol].first,-v[j].second,-v[lol].second,i});
}
}
int ror = (n/2)*k;
while(ror--){
fin+=pq.top()[0];
VIS[pq.top()[3]][-pq.top()[1]] = -1;
VIS[pq.top()[3]][-pq.top()[2]] = 0;
pq.pop();
}
long long fin2 = 0;
for(int i = 0;i<k;i++){
int mi[n],ma[n];
vector<array<int,5>> v;
long long overall = 0;
for(int j = 0;j<n;j++){
mi[j] = 1e18;
ma[j] = -1e18;
int MI = 0;
int MA = 0;
for(int w = 0;w<m;w++){
if(vis[j][w]!=-1||VIS[j][w]==-1)continue;
if(VIS[j][w]==1){
if(ma[j]<x[j][w]){
ma[j] = x[j][w];
MA = w;
}
}else{
if(mi[j]>x[j][w]){
mi[j] = x[j][w];
MI = w;
}
}
}
v.push_back({mi[j],ma[j],MI,MA,j});
}
int mim = 0;
for(int j = 0;j<n;j++){
if(v[j][0]==1e18){
vis[v[j][4]][v[j][3]] = i;
mim++;
}if(v[j][1]==-1e18){
vis[v[j][4]][v[j][2]] = i;
}
}
for(int j = 0;j<n;j++){
if(v[j][0]==1e18||v[j][1]==-1e18)continue;
if(mim<(n/2)){
vis[v[j][4]][v[j][2]] = i;
mim++;
}else{
vis[v[j][4]][v[j][3]] = i;
mim++;
}
}
}
if(fin!=fin2){
assert(0);
}
allocate_tickets(vis);
return fin;
}
Compilation message (stderr)
tickets.cpp: In function 'long long int find_maximum(int32_t, std::vector<std::vector<int> >)':
tickets.cpp:38:19: warning: unused variable 'overall' [-Wunused-variable]
38 | long long overall = 0;
| ^~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |