Submission #617749

#TimeUsernameProblemLanguageResultExecution timeMemory
617749OttoTheDino카니발 티켓 (IOI20_tickets)C++17
100 / 100
739 ms76100 KiB
#include "tickets.h"
#include <bits/stdc++.h>
using namespace std;

#define rep(i,s,e)                          for (int i = s; i <= e; ++i)
typedef long long ll;
typedef vector<int> vi;

long long find_maximum(int k, vector<vi> x) {
    ll n = x.size(), m = x[0].size(), cur = 0, cnt[n] = {}, id = 0;

    vector<vi> ans(n, vi(m, -1));

    priority_queue<pair<ll,ll>> pq; 

    rep (i,0,n-1) {
        rep (j,0,k-1) cur -= x[i][j];
        pq.push({x[i][k-1]+x[i][m-1], i});
    }

    rep (run,1,n*k/2) {
        ll val = pq.top().first, u = pq.top().second;
        pq.pop();
        cur += val;
        if (++cnt[u]<k) pq.push({x[u][k-1-cnt[u]]+x[u][m-1-cnt[u]], u});
    }

    rep (i,0,n-1) {
        rep (j,0,k-1) ans[i][(m-cnt[i]+j)%m] = (id+j)%k;
        id += cnt[i];
    }

    allocate_tickets(ans);

    return cur;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...