This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "tickets.h"
#include <vector>
#include <algorithm>
#include <set>
#define all(x) x.begin(), x.end()
using namespace std;
using i64 = long long int;
struct Ticket
{
int color;
int idx;
int value;
};
i64 find_maximum(int k, vector<vector<int>> x)
{
int n = x.size();
int m = x[0].size();
vector<Ticket> tickets;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
Ticket t;
t.color = i;
t.idx = j;
t.value = x[i][j];
tickets.push_back(t);
}
}
sort(all(tickets), [](const Ticket& l, const Ticket& r)
{
return l.value < r.value;
});
i64 ret = 0;
vector<vector<int>> ans(n, vector<int>(m, -1));
vector<int> lrm(m, n / 2), rrm(m, n / 2);
vector<set<int>> canUse(n);
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
canUse[i].insert(j);
int l = 0, r = n * m - 1;
while (l < r)
{
ret += tickets[r].value - tickets[l].value;
int lnxt = -1;
for (auto& c : canUse[tickets[l].color])
{
if (lrm[c] == 0)
continue;
lnxt = c;
break;
}
canUse[tickets[l].color].erase(lnxt);
lrm[lnxt]--;
ans[tickets[l].color][tickets[l].idx] = lnxt;
int rnxt = -1;
for (auto& c : canUse[tickets[r].color])
{
if (rrm[c] == 0)
continue;
rnxt = c;
break;
}
canUse[tickets[r].color].erase(rnxt);
rrm[rnxt]--;
ans[tickets[r].color][tickets[r].idx] = rnxt;
l++;
r--;
}
allocate_tickets(ans);
return ret;
}
# | 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... |