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;
const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
// #define int long long
#define ll long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
const int maxn = 1600;
int n, m, act[maxn], act1[maxn];
long long find_maximum (int k, std::vector<std::vector<int>> x) {
n = x.size();
m = x[0].size();
ll ans = -inf;
for(int j = 0; j < n; j++) {
for(int o = 0; o <= 1; o++) {
ll val;
if(o == 0) val = x[j][0];
else val = x[j][m-1];
priority_queue<pair<int,int>> pq;
//comeca com todos que da sendo menor
int q1 = 0;
int q2 = 0;
ll ans1 = 0;
for(int i = 0; i < n; i++) {
if(x[i][0] <= val) {
q1++;
ans1+= abs(x[i][0]-val);
act1[i] = 0;
if(x[i][m-1] >= val) pq.push(mp(abs(val-x[i][m-1]) - abs(x[i][0]-val),i));
}
else {
q2++;
act1[i] = m-1;
ans1+= abs(val-x[i][m-1]);
}
}
while(pq.size() && q1 != q2) {
int id = pq.top().sc;
pq.pop();
q2++;
q1--;
act1[id] = m-1;
ans1-= abs(x[id][0]-val);
ans1+= abs(val-x[id][m-1]);
}
if(q1 == q2 && ans1 >= ans) {
ans = ans1;
for(int i = 0; i < n; i++) {
act[i] = act1[i];
}
}
}
}
vector<vector<int>> s(n);
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
s[i].pb(-1);
}
s[i][act[i]] = 0;
}
// allocate_tickets(s);
return ans;
}
// int32_t main() {
// ios::sync_with_stdio(false); cin.tie(0);
// freopen("in.in", "r", stdin);
// // freopen("out.out", "w", stdout);
// int N,M,K; cin >> N >> M >> K;
// vector<vector<int>> x(N);
// for(int i = 0; i < N; i++) {
// for(int j = 0; j < M; j++) {
// int o; cin >> o;
// x[i].pb(o);
// }
// }
// cout << find_maximum(K,x);
// }
# | 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... |