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 st first
#define nd second
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
typedef pair<int, int> pii;
typedef long long ll;
long long find_maximum(int k, std::vector<std::vector<int>> x) {
int n = x.size();
int m = x[0].size();
int ile[n], ile2[n], uzy[n];
ll sum[n];
for(int i=0; i<n; i++){
uzy[i]=ile[i]=0;
ile2[i]=m-1;
sum[i]=0;
for(int j=0; j<k; j++){
sum[i]+=x[i][m-1-j];
}
}
ll ans=0;
std::vector<std::vector<int>> answer;
for (int i = 0; i < n; i++) {
std::vector<int> row(m);
answer.pb(row);
}
priority_queue<pair<pair<int, ll>, int> > Q;
for(int j=0; j<n; j++){
Q.push(mp(mp(x[j][ile[j]]+x[j][ile2[j]], sum[j]), j));
}
for(int i=0; i<k*n/2; i++){
auto a=Q.top();
Q.pop();
ans+=x[a.nd][ile2[a.nd]];
answer[a.nd][ile2[a.nd]]=i;
sum[a.nd]-=x[a.nd][ile2[a.nd]];
ile2[a.nd]--;
if(++uzy[a.nd]<k)Q.push(mp(mp(x[a.nd][ile[a.nd]]+x[a.nd][ile2[a.nd]], sum[a.nd]), a.nd));
}
priority_queue<pii> Q2;
while(Q.size())Q.pop();
for(int j=0; j<n; j++){
if(uzy[j]<k)Q2.push(mp(-x[j][ile[j]]-x[j][ile2[j]], j));
}
for(int i=0; i<k*n/2; i++){
pii a=Q2.top();
Q2.pop();
ans-=x[a.nd][ile[a.nd]];
answer[a.nd][ile[a.nd]]=i;
ile[a.nd]++;
if(++uzy[a.nd]<k)Q2.push(mp(-x[a.nd][ile[a.nd]]-x[a.nd][ile2[a.nd]], a.nd));
}
for(int i=1; i<=k; i++){
vector<int> todo;
int a=0, b=0;
for(int j=0; j<n; j++){
if(ile[j]==0)a++, answer[j][++ile2[j]]=i;
else if(ile2[j]==m-1)b++, answer[j][--ile[j]]=i;
else todo.pb(j);
}
for(int j:todo){
if(a<n/2){
a++;
answer[j][++ile2[j]]=i;
}
else{
b++;
answer[j][--ile[j]]=i;
}
}
}
for(auto &i:answer){
for(auto &j:i)j--;
}
allocate_tickets(answer);
return ans;
}
# | 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... |