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;
void allocate_tickets(vector<vector<int>>);
typedef pair<int,int> P;
long long find_maximum(int k, vector<vector<int> > x) {
int N = x.size();
int M = x[0].size();
vector<vector<int> > ans;
ans.resize(N);
int i,j;
for(i=0;i<N;i++) {
ans[i].resize(M);
fill(ans[i].begin(),ans[i].end(),-1);
}
long long int cnt = 0;
if(k==1) {
vector<int> pt1;
vector<int> pt2;
pt1.resize(N);
pt2.resize(N);
fill(pt2.begin(),pt2.end(),M-1);
int j, st;
for(j=0;j<k;j++) {
vector<P> V;
for(i=0;i<N;i++) {
V.push_back(P(x[i][pt2[i]]+x[i][pt1[i]],i));
}
sort(V.begin(),V.end());
for(i=0;i<N;i++) {
int n = V[i].second;
if(i < N / 2) {
ans[n][pt1[n]] = j;
cnt -= x[n][pt1[n]];
pt1[n]++;
}
else {
ans[n][pt2[n]] = j;
cnt += x[n][pt2[n]];
pt2[n]--;
}
}
}
allocate_tickets(ans);
return cnt;
}
else {
vector<P> A;
A.resize(N);
for(i=0;i<N;i++) {
for(j=0;j<M;j++) {
A[i].first += x[i][j];
}
A[i].second = i;
}
vector<int> pt1;
vector<int> pt2;
pt1.resize(N);
pt2.resize(N);
fill(pt2.begin(),pt2.end(),M-1);
sort(A.begin(),A.end(),[](P x, P y) {return x.first > y.first;});
for(i=0;i<k;i++) {
for(j=0;j<N;j++) {
if(j < N/2) {
ans[A[j].second][pt2[A[j].second]] = i;
cnt += x[A[j].second][pt2[A[j].second]];
A[j].first -= x[A[j].second][pt2[A[j].second]];
pt2[A[j].second]--;
}
else {
ans[A[j].second][pt1[A[j].second]] = i;
cnt -= x[A[j].second][pt1[A[j].second]];
A[j].first -= x[A[j].second][pt1[A[j].second]];
pt1[A[j].second]++;
}
}
sort(A.begin(),A.end(),[](P x, P y) {return x.first > y.first;});
}
allocate_tickets(ans);
return cnt;
}
}
Compilation message (stderr)
tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:26:16: warning: unused variable 'st' [-Wunused-variable]
26 | int j, st;
| ^~
# | 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... |