#include "tickets.h"
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
long long find_maximum(int k, vector<vector<int> > x){
int n=x.size(), m=x[0].size();
long long res=0;
vector<int> l(n, k-1), r(n, m-1);
vector<vector<int> > ans(n, vector<int>(m, -1));
vector<vector<pii> > vect(n, vector<pii>(m));
priority_queue<pii> pq;
for (int i=0; i<n; ++i){
for (int j=0; j<m; ++j)vect[i][j]=mp(x[i][j], j);
sort(vect[i].begin(), vect[i].end());
for (int j=0; j<k; ++j)res-=vect[i][j].fi, ans[i][vect[i][j].se]=j;
pq.push(mp(vect[i][l[i]].fi+vect[i][r[i]].fi, i));
}
for (int i=0; i<n*k/2; ++i){
pii c=pq.top();
pq.pop();
res+=c.fi;
ans[c.se][vect[c.se][r[c.se]].se]=ans[c.se][vect[c.se][l[c.se]].se];
if (l[c.se]!=r[c.se])ans[c.se][vect[c.se][l[c.se]].se]=-1;
--l[c.se];
--r[c.se];
if (l[c.se]>=0)pq.push(mp(vect[c.se][l[c.se]].fi+vect[c.se][r[c.se]].fi, c.se));
}
allocate_tickets(ans);
return res;
}
# | 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... |