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;
long long find_maximum(int k, vector<vector<int>> x) {
int n = x.size(), m = x[0].size();
vector<vector<int>> answer(n, vector<int>(m, -1));
vector<deque<pair<int, int>>> t(n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
t[i].push_back({x[i][j], j});
}
sort(t[i].begin(), t[i].end());
}
long long int ans = 0;
for (int c = 0; c < k; c++) {
vector<int> arr, vis(n, 0);
vector<tuple<int, int, int>> a;
for (int i = 0; i < n; i++) {
a.push_back({t[i].back().first, i, t[i].back().second});
if (t[i].size() > 1) {
a.push_back({t[i].front().first, i, t[i].front().second});
}
}
sort(a.rbegin(), a.rend());
for (int ind = 0; ind < a.size(); ind++) {
auto [v, i, j] = a[ind];
if (arr.size() == n/2) {
break;
}
if (vis[i]) {
continue;
}
vis[i] = 1;
if (t[i].back().second == j) {
t[i].pop_back();
} else {
t[i].pop_front();
}
answer[i][j] = c;
arr.push_back(v);
}
reverse(a.begin(), a.end());
for (int ind = 0; ind < a.size(); ind++) {
auto [v, i, j] = a[ind];
if (vis[i]) {
continue;
}
vis[i] = 1;
if (t[i].back().second == j) {
t[i].pop_back();
} else {
t[i].pop_front();
}
answer[i][j] = c;
arr.push_back(v);
}
sort(arr.begin(), arr.end());
int med = arr[n/2-1];
for (int i = 0; i < n; i++) {
ans += abs(arr[i]-med);
}
}
allocate_tickets(answer);
return ans;
}
Compilation message (stderr)
tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:25:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<int, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for (int ind = 0; ind < a.size(); ind++) {
| ~~~~^~~~~~~~~~
tickets.cpp:27:28: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
27 | if (arr.size() == n/2) {
| ~~~~~~~~~~~^~~~~~
tickets.cpp:43:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<int, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for (int ind = 0; ind < a.size(); ind++) {
| ~~~~^~~~~~~~~~
# | 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... |