Submission #448222

#TimeUsernameProblemLanguageResultExecution timeMemory
448222dxz05Carnival Tickets (IOI20_tickets)C++14
27 / 100
3061 ms51364 KiB
#include "tickets.h"
#include <bits/stdc++.h>

typedef long long ll;

#define MP make_pair

using namespace std;

long long find_maximum(int k, vector<vector<int>> a) {
	int n = a.size();
	int m = a[0].size();

	ll ans = 0;

    vector<vector<int>> answer(n, vector<int>(m, -1));

    for (int it = 0; it < k; it++) {
        vector<pair<pair<ll, int>, pair<int, int>>> v;
        for (int i = 0; i < n; i++) {
            int l = -1, r = -1;
            for (int j = 0; j < m; j++){
                if (answer[i][j] != -1) continue;
                if (l == -1 || a[i][j] < a[i][l]) l = j;
                if (r == -1 || a[i][j] > a[i][r]) r = j;
            }
            answer[i][r] = it;
            ans += a[i][r];
            v.emplace_back(MP(-a[i][r] - a[i][l], i), MP(l, r));
        }

        sort(v.rbegin(), v.rend());

        for (int i = 0; i < n / 2; i++) {
            ans += v[i].first.first;
            answer[v[i].first.second][v[i].second.second] = -1;
            answer[v[i].first.second][v[i].second.first] = it;
        }

    }

    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...