이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "tickets.h"
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> ans;
// 1 5
// 10 10
// 8 12
// 12 20
long long find_maximum(int k, std::vector<std::vector<int>> x) {
int n = x.size();
int m = x[0].size();
ans = vector<vector<int>>(n, vector<int>(m, -1));
long long res = 0;
for (int r = 0; r < k; r++) {
set<pair<int, int>> low, high;
vector<pair<int, int>> a(n);
for (int i = 0; i < n; i++) {
int mn = -1;
int mx = -1;
for (int j = 0; j < m; j++)
if (ans[i][j] == -1) {
if (mn == -1 || x[i][j] < x[i][mn]) mn = j;
if (mx == -1 || x[i][j] > x[i][mx]) mx = j;
}
low.insert({x[i][mn], i});
high.insert({x[i][mx], i});
a[i] = {mn, mx};
}
vector<int> v;
while (low.size() > 0) {
int diff = 0;
int idx1 = -1, idx2 = -1;
// try min first
auto it1 = low.begin();
auto it2 = high.rbegin();
if (it1->second == it2->second) {
it2++;
}
assert(it2->first >= it1->first);
diff = it2->first - it1->first;
idx1 = it1->second;
idx2 = it2->second;
// try max first
it1 = low.begin();
it2 = high.rbegin();
if (it1->second == it2->second) {
it1++;
}
assert(it2->first >= it1->first);
if (it2->first - it1->first > diff) {
diff = it2->first - it1->first;
idx1 = it1->second;
idx2 = it2->second;
}
ans[idx1][a[idx1].first] = r;
ans[idx2][a[idx2].second] = r;
v.push_back(x[idx1][a[idx1].first]);
v.push_back(x[idx2][a[idx2].second]);
low.erase({x[idx1][a[idx1].first], idx1});
low.erase({x[idx2][a[idx2].first], idx2});
high.erase({x[idx1][a[idx1].second], idx1});
high.erase({x[idx2][a[idx2].second], idx2});
}
sort(v.begin(), v.end());
for (int i = 0; i < ((int)v.size() - 1 - i); i++) {
res += v[v.size() - 1 - i] - v[i];
}
}
allocate_tickets(ans);
return res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |