| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 1186998 | woohyun_jng | Naan (JOI19_naan) | C++20 | 0 ms | 0 KiB | 
#include <bits/stdc++.h>
#define int long long
#define __int128_t ll
using namespace std;
typedef array<int, 2> fr;
const int MAX = 2001;
int V[MAX][MAX], S[MAX];
fr D[MAX][MAX];
bool chk[MAX];
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int N, L, S, X, Y;
    fr K;
    vector<int> P;
    cin >> N >> L;
    for (int i = 1; i <= N; i++) {
        S = X = Y = 0;
        for (int j = 1; j <= L; j++)
            cin >> V[i][j], S += V[i][j];
        for (int j = 1; j <= N - 1; j++) {
            while (S * j >= N * (Y + V[i][X + 1]))
                Y += V[i][++X];
            D[i][j] = {S * j - N * Y + X * N * V[i][X + 1], N * V[i][X + 1]};
        }
        D[i][N] = {0, 0};
    }
    for (int i = 1; i <= N; i++) {
        K = {MAX, 1}, X = -1;
        for (int j = 1; j <= N; j++) {
            if (chk[j])
                continue;
            if (comp(D[j][i], K))
                K = D[j][i], X = j;
        }
        if (i < N)
            cout << K[0] << ' ' << K[1] << '\n';
        P.push_back(X), Y = K[1], chk[X] = true;
    }
    for (int i : P)
        cout << i << ' ';
    cout << '\n';
    return 0;
}
