#include "tickets.h"
#include <iostream>
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
int inf = 1e9 + 7;
ll find_maximum(int k, vector<vector<int>> x) {
    int n = x.size();
    int m = x[0].size();
    vector<vector<pair<ll, ll>>> a(n, vector<pair<ll, ll>>(m));
    vector<vector<int>> result(n, vector<int>(m, -1));
    ll res = 0;
    vector<vector<int>> big(n), sma(n);
    vector<vector<ll>> stuff;
    for (int i = 0; i < n; i++) {
        for (int j =0; j < m; j++) {
            a[i][j] = {x[i][j], j};
        }
        sort(a[i].rbegin(), a[i].rend());
        ll sum = 0;
        for (int j = 0; j < k; j++) {
            sum += a[i][j].fi;
            result[i][a[i][j].se] = 1;
        }
        for (int j = k - 1; j >= 0; j--) {
            int ind = m - (k - j);
            stuff.push_back({-a[i][j].fi - a[i][ind].fi, j, ind, i});
        }
        res += sum;
    }
    sort(stuff.rbegin(), stuff.rend());
    for (int j = 0; j < n * k / 2; j++) {
        res += stuff[j][0];
        result[stuff[j][3]][a[stuff[j][3]][stuff[j][1]].se] = -1;
        result[stuff[j][3]][a[stuff[j][3]][stuff[j][2]].se] = 0;
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (result[i][j] == 1) {
                big[i].push_back(j);
            } else if (result[i][j] == 0) {
                sma[i].push_back(j);
            }
        }
    }
    vector<pair<int, int>> numb(k), newb;
    for (int i = 0; i < k; i++) {
        numb[i] = {0, i};
    }
    for (int i = 0; i < n; i++) {
        sort(numb.begin(), numb.end());
        newb.clear();
        int ind = 0;
        for (auto el : big[i]) {
            result[i][el] = numb[ind].se;
            newb.push_back({numb[ind].fi + 1, numb[ind].se});
            ind++;
        }
        for (auto el : sma[i]) {
            result[i][el] = numb[ind].se;
            newb.push_back(numb[ind]);
            ind++;
        }
        numb = newb;
    }
    allocate_tickets(result);
    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... |