Submission #1148955

#TimeUsernameProblemLanguageResultExecution timeMemory
1148955weakweakweakNaan (JOI19_naan)C++20
24 / 100
1 ms328 KiB
// 2520
// target 24
#include <bits/stdc++.h>
using namespace std;
#define int long long
using pii = pair<int,int>;
#define fs first 
#define sc second

int n, l, a[7][2010], target[2010] = {0};
int B = 2520;
vector<int> perm;

void solve() {
    int i = 0, j = 0;
    vector<pii> pos;
    for (int id = 1; id <= n; id++) {
        bool y = 0;
        long long me = target[id];
        while (i <= l) {
            if (a[id][i]*(B-j) < me) {
                me -= a[id][i]*(B-j);
                i++, j = 0;
            }
            else {
                int ll = j+1, rr = B;
                while (ll < rr) {
                    int mid = (ll+rr) / 2;
                    if (a[id][i] * (mid-j) >= me) rr = mid;
                    else ll = mid+1;
                }
                pos.push_back({i,ll});
                if (ll == B) i++, j = 0;
                else j = ll;
                y = 1;
                break;
            }
        }
        if (!y) return;
    }
    pos.pop_back();
    for (auto p : pos) {
        cout << p.fs*B+p.sc << ' ' << B << '\n';
    }
    for (int x : perm) cout << x << ' '; cout << '\n';
    exit(0);
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n >> l;
    B *= n;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < l; j++) {
            cin >> a[i][j];
            target[i] += a[i][j] * B;
        }
        target[i] /= n;
        a[i][l] = target[i];
    }
    for (int i = 1; i <= n; i++) perm.push_back(i);
    do {
        solve();
    }   while (next_permutation(perm.begin(), perm.end()));
    cout << "-1\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...