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;
using ll=long long;
#define R(i,n,...) for(int i=__VA_ARGS__+0; i<(n); ++i)
struct pii {
int x, i, j;
bool operator<(const pii b) const { return x<b.x; }
};
ll find_maximum(int K, vector<vector<int>> A) {
const int N=A.size();
const int M=A[0].size();
const int X=N*K/2;
ll sum=0;
vector<pii> B(N*K);
R(i, N) {
R(j, K) {
sum+=A[i][M-K+j];
B[i*K+j]={A[i][M-K+j]+A[i][j], i, j};
}
fill(begin(A[i]), end(A[i]), -1);
}
sort(begin(B), end(B));
vector<int> C(N), D(K), E(K);
int st=0;
R(i, X) sum-=B[i].x, C[B[i].i]++;
R(i, N) {
int k=0, ed=st+C[i], cnt=0;
R(j, K-C[i]) {
while((st<=k && k<ed) || E[k]==N/2) k++;
++E[A[i][M-j-1]=k++];
}
R(j, C[i]) cnt+=++D[A[i][j]=st+j]==N/2;
st+=cnt;
}
allocate_tickets(A);
return sum;
}
# | 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... |