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 "tickets.h"
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define pipii pair<int,pair<int,int>>
#define pq priority_queue
#define vi vector<int>
#define vii vector<vector<int>>
#define v vector
long long find_maximum(int k, vii x) {
int out=0;
int n=x.size();//num colours
int m=x[0].size();//num of each colour
pq<pipii> mi;
v<v<pipii>> l(n);
v<v<pipii>> s(n);
vii answer(n,vi(m,-1));
for(int i=0;i<n;i++){//initilize long list
pq<pipii> ma;
for(int j=0;j<m;j++){
ma.push({x[i][j],{i,j}});
mi.push({-x[i][j],{i,j}});
}
for(int j=0;j<k;j++){
pipii cur=ma.top();
ma.pop();
l[i].push_back(cur);
}
}
int count=0;
while(count<k*n/2){//transfer to short list
pipii cur = mi.top();
mi.pop();
int ind=cur.second.first;
if(x[ind].size()>0){
l[ind].pop_back();
s[ind].push_back({-cur.first,cur.second});
count++;
}
}
for(int i=0;i<k;i++){//allocate
int sm=0;
int la=0;
for(int j=0;j<n;j++){
if(sm==n/2){
pipii cur=l[j][l[j].size()-1];
answer[j][cur.second.second]=i;
l[j].pop_back();
out+=cur.first;
la++;
}
else if(la==n/2){
pipii cur=s[j][s[j].size()-1];
answer[j][cur.second.second]=i;
s[j].pop_back();
out-=cur.first;
sm++;
}
else if(l[j].size()>0){
pipii cur=l[j][l[j].size()-1];
answer[j][cur.second.second]=i;
l[j].pop_back();
out+=cur.first;
la++;
}
else{
pipii cur=s[j][s[j].size()-1];
answer[j][cur.second.second]=i;
s[j].pop_back();
out-=cur.first;
sm++;
}
}
}
allocate_tickets(answer);
return out;
}
# | 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... |