#include "tickets.h"
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
ll find_maximum(int k, vector<vector<int>> a) {
    int n = a.size();
    int m = a[0].size();
    vector<vector<ll>> pref(n + 1, vector<ll>(m + 1));
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            pref[i][j] = pref[i][j - 1] + a[i - 1][j - 1];
        }
    }
    auto smallest = [&](int i, int k) {
        return pref[i][k];
    };
    auto biggest = [&](int i, int k) {
        return pref[i][m] - pref[i][m - k];
    };
    vector<vector<int>> who(n + 1, vector<int>(n * k / 2 + 1, 0));
    vector<ll> dp(n * k / 2 + 1, -1e18);
    dp[0] = 0;
    for (int i = 1; i <= n; i++) {
        vector<ll> ndp(n * k / 2 + 1, -1e18);
        for (int j = 0; j <= n * k / 2; j++) {
            for (int h = 0; h <= k && h <= j; h++) {
                if (ndp[j] < dp[j - h] + biggest(i, h) - smallest(i, k - h)) {
                    ndp[j] = dp[j - h] + biggest(i, h) - smallest(i, k - h);
                    who[i][j] = h;
                }
            }
        }
        swap(dp, ndp);
    }
    vector<vector<int>> sol(n, vector<int>(m, -1));
    ll ans = dp[n * k / 2];
    int i = n;
    int j = n * k / 2;
    while (i > 0 && j > 0) {
        int x = who[i][j];
        int r = i % k;
        for (int it = 0; it < m; it++) {
            if (it < k - x || m - it <= x) {
                sol[i - 1][it] = r++;
                r %= k;
            }
        }
        i--;
        j -= x;
    }
    allocate_tickets(sol);
    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... |