# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
304604 | lolicon | Carnival Tickets (IOI20_tickets) | C++14 | 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 "tickets.h"
#include <bits/stdc++.h>
using namespace std;
#define all(x) begin(x), end(x)
long long find_maximum(int k, vector<vector<int>> x) {
int n = x.size();
int m = x[0].size();
vector<vector<int>> ans;
for (int i = 0; i < n; i++) {
vector<int> row(m, -1);
ans.push_back(row);
}
set<int> st;
vector<pair<int, int>> v;
for(int i = 0; i < n; i++) {
v.emplace_back(x[i][0], i);
v.emplace_back(x[i][m - 1], i);
}
int l, r;
sort(all(v));
for(int i = 0; i < 2 * n; i++) {
st.insert(v[i].second);
if(st.size() == n / 2) {
p = i;
break;
}
}
st.clear();
for(int i = 0; i <= p; i++) {
if(!st.count(v[i].second))
ans[v[i].second][0] = 0;
st.insert(v[i].second);
}
for(int i = 2 * n - 1; i > p; i--) {
if(!st.count(v[i].second))
ans[v[i].second][m - 1] = 0;
st.insert(v[i].second);
}
// cal
long long ret = 0;
vector<vector<int>> T(k);
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
if(ans[i][j] != -1) {
T[ans[i][j]].push_back(x[i][j]);
}
}
}
for(int i = 0; i < k; i++) {
sort(begin(T[i]), end(T[i]));
int p = T[i][n / 2];
for(int j = 0; j < n; j++) {
ret = ret + (long long)abs(p - T[i][j]);
}
}
allocate_tickets(ans);
/*for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
cout << ans[i][j] << " \n"[j == m - 1];
}
}*/
return ret;
}