# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
301200 | 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>
//#include "tickets.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<vector<int> > ans(n, vector<int>(m, -1));
vector<pair<long long, pair<int, int> > > moo;
long long res = 0;
for (int e = 0; e < k; e++)
{
for (int i = 0; i < n; i++)
{
ans[i][e] = e;
res -= x[i][e];
moo.push_back({x[i][e] + x[i][e + m - k], {i, e}});
}
}
sort(moo.begin(), moo.end());
reverse(moo.begin(), moo.end());
for (int i = 0; i < n / 2 * k; i++)
{
int a = moo[i].second.first;
int b = moo[i].second.second;
res += moo[i].first;
ans[a][b + m - k] = ans[a][b];
ans[a][b] = -1;
}
//allocate_tickets(ans);
return res;
}
int main()
{
int n, m, k;
cin >> n >> m >> k;
vector<vector<int> > x(n, vector<int>(m));
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
cin >> x[i][j];
}
}
cout << find_maximum(k, x);
}