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 <vector>
#include <cmath>
#include <algorithm>
#include <set>
using namespace std;
using ll = long long;
ll n, m;
long long find_maximum(int k, vector<vector<int>> x) {
n = x.size();
m = x[0].size();
vector<vector<int>>anss(n, vector<int>(m, -1));
vector<set<pair<ll, int>>> v(n);
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
v[i].insert({ x[i][j], j });
}
}
ll ans = 0;
for (int i = 0; i < k; i++)
{
vector<ll> q;
for (int j = 0; j < n/2; j++)
{
q.push_back(v[j].begin()->first);
anss[j][v[j].begin()->second] = i;
v[j].erase(v[j].begin());
}
for (int j = n/2; j < n; j++)
{
q.push_back((--v[j].end())->first);
anss[j][(--v[j].end())->second] = i;
v[j].erase(--v[j].end());
}
for (int j = 0; j < n; j++)
{
ans += abs(q[j] - q[n / 2]);
}
}
allocate_tickets(anss);
return ans;
}
//6 1 1
//1 2 3 4 5 6
//#include "tickets.h"
//#include <vector>
//#include <cmath>
//using namespace std;
//using ll = long long;
//ll n;
//ll qaq(vector<ll> qaqa)
//{
// ll polni = 1000000000000000000LL;
// for (int i = 0; i < qaqa.size(); i++)
// {
// ll chsh = 0;
// for (int j = 0; j < qaqa.size(); j++)
// {
// chsh += abs(qaqa[i] - qaqa[j]);
// }
// polni = min(polni, chsh);
// }
// return polni;
//}
//
//long long find_maximum(int k, vector<vector<int>> x) {
// n = x.size();
// vector<ll>zibil;
// vector<vector<int>>ans(n, vector<int>(1, 0));
// for (int i = 0; i < n; i++) {
// zibil.push_back(x[i][0]);
// }
// allocate_tickets(ans);
// return qaq(zibil);
//}
# | 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... |