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;
long long find_maximum(int k, vector<vector<int>> x) {
    int n = x.size();
    int m = x[0].size();
    vector<vector<int>> s {x};
    for (auto& e1 : s) {
        for (auto& e2 : e1) e2 = -1;
    }
    vector<vector<tuple<int,int,int>>> v;
    for (int i = 0; i < n; i++) {
        v.push_back({});
        for (int j = 0; j < m; j++) {
            v[i].push_back({x[i][j], j, i});
        }
    }
    for (auto& sv : v) sort(sv.begin(), sv.end());
    sort(v.begin(), v.end());
    for (int i = n/2; i < n; i++) {
        sort(v[i].rbegin(), v[i].rend());
    }
    
    long long result = 0ll;
    bool extracase = (k%2);
    if (extracase) k -= 1;
    for (int i = 0; i < k/2; i++) {
        int nb0 = 0; int nb1 = 0;
        int nb0m = 0; int nb1m = 0;
        for (int j = 0; j < n; j++) {
            int a, b, c;
            tie(a, b, c) = v[j][i];
            s[c][b] = i;
            if (a == 0) {
                nb0 += 1;
            }
            else {
                nb1 += 1;
            }
            int d, e, f;
            tie(d,e,f) = v[j][m-i-1];
            s[f][e] = k-i-1;
            if (d == 0) {
                nb0m += 1;
            }
            else {
                nb1m += 1;
            }
        }
        result += min(nb0, nb1); result += min(nb0m, nb1m);
    }
    if (extracase) {
        int nb0 = 0; int nb1 = 0;
        int nb0m = 0; int nb1m = 0;
        for (int j = 0; j < n; j++) {
            if (get<0>(v[j][k/2]) == 0) {
                nb0 += 1;
            }
            else {
                nb1 += 1;
            }
            if (get<0>(v[j][m - k/2 - 1]) == 0) {
                nb0m += 1;
            }
            else {
                nb1m += 1;
            }
        }
        int result1 = min(nb0, nb1); int result2 = min(nb0m, nb1m);
        if (result1 > result2) {
            for (int j = 0; j < n; j++) {
                s[get<2>(v[j][k/2])][get<1>(v[j][k/2])] = k;
            }
        }
        else {
            for (int j = 0; j < n; j++) {
                s[get<2>(v[j][m - k/2 - 1])][get<1>(v[j][m - k/2 - 1])] = k;
            }
        }
        result += max(result1, result2);
    }
    allocate_tickets(s);
    return result;
}
| # | 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... |