제출 #576733

#제출 시각아이디문제언어결과실행 시간메모리
576733SlavicG카니발 티켓 (IOI20_tickets)C++17
27 / 100
544 ms71228 KiB
#include "bits/stdc++.h"
#include "tickets.h"
using namespace std;

#define ll long long
#define sz(a) (int)a.size()
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define forn(i, n) for(int i=0;i < n; ++i)

long long find_maximum(int k, std::vector<std::vector<int>> x) {
	int n = x.size();
	int m = x[0].size();
	std::vector<std::vector<int>> answer(n, vector<int>(m, -1));
	deque<pair<int, int>> d[n];

    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < m; ++j) {
            d[i].pb({x[i][j], j});
        }
        sort(all(d[i]));
    }
    ll ans = 0;

    for(int kk = 0; kk < k; ++kk) {
        priority_queue<pair<int, int>> q;
        forn(i, n) q.push({d[i].front().first + d[i].back().first, i});

        for(int j = 0; j < n / 2; ++j) {
            int i = q.top().second;
            q.pop();
            answer[i][d[i].back().second] = kk;
            ans += d[i].back().first;
            d[i].pop_back();
        }
        for(int j = 0; j < n / 2; ++j) {
            int i = q.top().second;
            q.pop();
            answer[i][d[i].front().second] = kk;
            ans -= d[i].front().first;
            d[i].pop_front();
        }
    }

    allocate_tickets(answer);
	return ans;
}
#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...