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 ll = long long;
using namespace std;
ll find_maximum(int k, vector<vector<int>> t) {
int n = t.size(), m = t[0].size();
vector<int> all;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
all.push_back(t[i][j]);
}
}
sort(all.begin(), all.end());
int middle = all[all.size() / 2];
ll res = 0;
vector<pair<ll, int>> a(n);
vector<int> bg(n, 0), end(n, m - 1);
vector<vector<int>> s(n, vector<int>(m, -1));
for (int i = 0; i < n; i++) {
a[i].first = 0;
a[i].second = i;
for (int j = 0; j < m; j++) {
t[i][j] -= middle;
}
}
for (int st = 0; st < k; st++) {
vector<pair<int, int>> l, r;
for (int i = 0; i < n; i++) {
if (abs(t[i][bg[i]]) > abs(t[i][end[i]])) {
if (t[i][end[i]] < 0) {
l.emplace_back(INT32_MAX, i);
} else {
l.emplace_back(abs(abs(t[i][bg[i]]) - abs(t[i][end[i]])), i);
}
} else {
if (t[i][bg[i]] > 0) {
l.emplace_back(INT32_MAX, i);
} else {
l.emplace_back(abs(abs(t[i][bg[i]]) - abs(t[i][end[i]])), i);
}
}
}
sort(l.begin(), l.end(), greater<>());
sort(r.begin(), r.end(), greater<>());
set<int> li, ri;
for (auto [w, i] : l) {
li.insert(i);
}
for (auto [w, i] : r) {
ri.insert(i);
}
while (l.size() > n / 2) {
li.erase(l.back().second);
ri.insert(l.back().second);
l.pop_back();
}
while (r.size() > n / 2) {
ri.erase(r.back().second);
li.insert(r.back().second);
r.pop_back();
}
vector<int> nw;
for (int i : li) {
s[i][bg[i]] = st;
nw.push_back(t[i][bg[i]++]);
}
for (int i : ri) {
s[i][end[i]] = st;
nw.push_back(t[i][end[i]--]);
}
sort(nw.begin(), nw.end());
for (int i : nw) {
res += abs(i);
}
assert(0 >= nw[n / 2 - 1] && 0 <= nw[n / 2]);
}
allocate_tickets(s);
return res;
}
Compilation message (stderr)
tickets.cpp: In function 'll find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:55:25: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
55 | while (l.size() > n / 2) {
| ~~~~~~~~~^~~~~~~
tickets.cpp:60:25: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
60 | while (r.size() > n / 2) {
| ~~~~~~~~~^~~~~~~
# | 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... |