# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
301021 | IgorI | Carnival Tickets (IOI20_tickets) | C++17 | 0 ms | 0 KiB |
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 <bits/stdc++.h>
using namespace std;
long long find_maximum(int k, std::vector<std::vector<int>> x)
{
int n = x.size(), m = x[0].size();
vector<int> fr(n), to(n, m - 1);
vector<vector<int> > ans(n, vector<int>(m, -1));
long long res = 0;
for (int e = 0; e < k; e++)
{
long long cur = 0;
vector<pair<long long, int> > upd;
for (int i = 0; i < n; i++)
{
cur -= x[i][fr[i]];
upd.push_back({x[i][fr[i]] + x[i][to[i]], i});
}
sort(upd.begin(), upd.end());
reverse(upd.begin(), upd.end());
for (int i = 0; i < n / 2; i++)
{
cur += upd[i].first;
int id = upd[i].second;
ans[id][to[id]] = e;
to[id]--;
}
for (int i = n / 2; i < n; i++)
{
int id = upd[i].second;
ans[id][fr[id]] = e;
fr[id]++;
}
res += cur;
}
allocate_tickets(ans);
return res;
}