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"
#define FOR(i, begin, end) for(int i=(begin); i<(end); i++)
#define le(x) ((x)[((int)(x).size())-1])
#define sz(x) ((int)((x).size()))
#define pb push_back
#define s second
#define f first
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const int MxN=1510, INF=1e9;
int n, m, li[MxN], ri[MxN];
long long find_maximum(int k, std::vector<std::vector<int>> x) {
n=sz(x); m=sz(x[0]);
FOR(i, 0, n) ri[i]=m-1;
ll ret=0;
vector s(n, vector(m,-1));
vector<pair<vector<int>,int>> vec;
vi now;
FOR(r, 0, k) {
vec.clear();
FOR(i, 0, n) vec.pb({x[i],i});
sort(vec.begin(), vec.end());
FOR(i, 0, n/2) {
int in1=vec[i].s, in2=vec[n-1-i].s;
int val1=x[in1][0], val2=le(x[in2]);
s[in1][li[in1]++]=s[in2][ri[in2]--]=r;
x[in1].erase(x[in1].begin());
x[in2].erase(prev(x[in2].end()));
now.pb(val1); now.pb(val2);
}
}
sort(now.begin(), now.end());
int md=now[sz(now)/2];
for(auto it : now) {
ret+=abs(it-md);
}
allocate_tickets(s);
return ret;
}
/*
2 3 2
0 2 5
1 1 3
4 2 1
5 9
1 4
3 6
2 7
4 4 1
0 1 2 9
4 4 4 5
3 3 3 7
3 4 4 4
4 2 1
0 10
1 5
0 6
0 6
4 4 1
0 1 2 9
7 7 7 7
7 7 7 7
7 7 7 7
8 2 1
1 9
0 10
2 3
3 4
6 8
1 5
0 2
3 4
4 3 2
0 1 1
1 1 1
0 0 1
0 0 0
4 2 2
0 1
0 1
0 0
1 1
4 2 1
0 1
0 0
0 0
1 1
4 3 2
0 0 0
0 1 1
0 1 1
1 1 1
*/
# | 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... |