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;
typedef long long ll;
ll sub1(int k, vector<vector<int>> x) {
vector<int> s(x.size());
for (int i = 0; i < x.size(); i++) s[i] = x[i][0];
sort(s.begin(), s.end());
ll median = s[s.size() / 2];
ll sum = 0;
for (auto &e : s) sum += abs(e - median);
allocate_tickets(vector<vector<int>>(s.size(), vector<int>(1)));
return sum;
}
ll sub2(int k, vector<vector<int>> x) {
ll n = x.size(), m = x[0].size();
vector<pair<ll, ll>> avgId(n);
for (int i = 0; i < n; i++) {
avgId[i] = {x[i].front() + x[i].back(), i};
}
sort(avgId.begin(), avgId.end());
vector<ll> choices(n);
vector<vector<int>> res(n, vector<int>(m, -1));
ll median = 0;
for (int i = 0; i < n/2; i++) {
choices[i] = x[avgId[i].second].front();
res[avgId[i].second].front() = 0;
median = max(median, choices[i]);
}
for (int i = n/2; i < n; i++) {
choices[i] = x[avgId[i].second].back();
res[avgId[i].second].back() = 0;
}
ll sum = 0;
for (auto &e : choices) sum += abs(e - median);
allocate_tickets(res);
return sum;
}
ll find_maximum(int k, vector<vector<int>> x) {
if (k > 1) return sub1(k, x);
return sub2(k, x);
}
Compilation message (stderr)
tickets.cpp: In function 'll sub1(int, std::vector<std::vector<int> >)':
tickets.cpp:9:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
9 | for (int i = 0; i < x.size(); i++) s[i] = x[i][0];
| ~~^~~~~~~~~~
# | 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... |