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;
vector<vector<int> > mas, ans;
vector<vector<pair<int, int> > > maz, did, pos;
long long check(int n, int m, int k) {
vector<vector<int> > vec(m);
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
if(ans[i][j] == -1) continue;
vec[ans[i][j]].push_back(mas[i][j]);
}
}
long long ret = 0;
for(int i = 0; i < k; i++) {
sort(vec[i].begin(), vec[i].end());
for(int j = 0; j < vec[i].size(); j++) {
if(j < vec[i].size() / 2) {
ret -= vec[i][j];
}else {
ret += vec[i][j];
}
}
}
return ret;
}
/*
2 3 3
1 2 3
3 1 4
*/
long long find_maximum(int k, vector<vector<int> > x) {
int n = x.size();
int m = x[0].size();
mas = ans = x;
for(auto &x : ans) for(auto &y : x) y = -1;
maz.resize(n); did.resize(n); pos.resize(n);
long long sum = 0;
priority_queue<pair<long long, int> > q;
for(int i = 0; i < n; i++) {
vector<pair<int, int> > dd, mm;
for(int j = 0; j < m; j++) {
dd.push_back({x[i][j], j});
mm.push_back({x[i][j], j});
}
sort(mm.begin(), mm.end());
sort(dd.begin(), dd.end());
reverse(dd.begin(), dd.end());
for(int j = 0; j < k; j++) {
sum -= mm[j].first;
maz[i].push_back(mm[j]);
pos[i].push_back(dd[j]);
}
reverse(pos[i].begin(), pos[i].end());
q.push({pos[i].back().first + maz[i].back().first, i});
}
//cout << "kai visi minusai, sum = " << sum << endl;
for(int i = 0; i < n * k / 2; i++) {
long long pl = q.top().first;
int ind = q.top().second;
q.pop();
sum += pl;
//cout << "taciau galiu paimti ir sukeisti eileje " << ind << ", " << maz[ind].back().second << " su " << pos[ind].back().second << endl;
maz[ind].pop_back();
did[ind].push_back(pos[ind].back());
pos[ind].pop_back();
if(pos[ind].size()) {
q.push({pos[ind].back().first + maz[ind].back().first, ind});
}
}
/*cout << "taigi:\n";
for(int i = 0; i < n; i++) {
cout << "eileje " << i << ", minusai: "; for(auto &x : maz[i]) cout << x.second << " ";
cout << ", pliusai: "; for(auto x : did[i]) cout << x.second << " ";
cout << endl;
}*/
/*
for(int i = 0; i < n; i++) {
for(auto &x : maz[i]) ans[]
} */
vector<pair<int, int> > bal (k);
for(int i = 0; i < k; i++) {
bal[i] = {0, i};
}
// cout << "start" << endl;
for(int i = 0; i < n; i++) {
int i1 = 0; int i2 = 0;
for(int jj = 0; jj < k; jj++) {
int j = bal[jj].second;
if(i1 == did[i].size()) {
ans[i][maz[i][i2].second] = j;
i2++;
}else {
if(bal[jj].first != n / 2) {
ans[i][did[i][i1].second] = j;
i1++;
bal[jj].first++;
}else {
// cout << "i2 = " << i2 << ", maz[i].size() = " << maz[i].size() << endl;
ans[i][maz[i][i2].second] = j;
i2++;
}
}
}
sort(bal.begin(), bal.end());
}
allocate_tickets(ans);
//auto turi = check(n, m,k);
//cout << "turi " << turi << endl;
return sum;
/*
2 3 2
0 2 5
1 1 3
4 2 1
5 9
1 4
3 6
2 7
*/
//allocate_tickets(answer);
}
Compilation message (stderr)
tickets.cpp: In function 'long long int check(int, int, int)':
tickets.cpp:17:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for(int j = 0; j < vec[i].size(); j++) {
| ~~^~~~~~~~~~~~~~~
tickets.cpp:18:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | if(j < vec[i].size() / 2) {
| ~~^~~~~~~~~~~~~~~~~~~
tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:93:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
93 | if(i1 == did[i].size()) {
| ~~~^~~~~~~~~~~~~~~~
# | 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... |