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();
}
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(mi[j]>x[j][w]){
mi[j] = x[j][w];
MI = w;
}if(ma[j]<x[j][w]){
ma[j] = x[j][w];
MA = w;
}
}
v.push_back({mi[j],ma[j],MI,MA,j});
}
sort(v.begin(),v.end());
priority_queue<array<int,4>> pq;
for(auto j:v){
vis[j[4]][j[3]] = i;
overall+=j[1];
pq.push({-j[1]-j[0],j[2],j[3],j[4]});
}
int nah = n/2;
while(nah--){
vis[pq.top()[3]][pq.top()[2]] = -1;
vis[pq.top()[3]][pq.top()[1]] = i;
overall+=pq.top()[0];
pq.pop();
}
}
allocate_tickets(vis);
return fin;
}
# | 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... |