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 <bits/stdc++.h>
using namespace std;
#define ll long long
ll find_ans(vector<int> cur)
{
sort(begin(cur),end(cur));
vector<ll> pre={0};
for(auto i:cur)
pre.push_back(pre.back()+(ll)i);
ll mi=2e18;
int n=cur.size();
for(int i=0;i<n;i++)
{
ll x=cur[i];
mi=min(mi,(x*i)-pre[i] + (pre[n]-pre[i])-((x*(n-i))));
}
return mi;
}
long long find_maximum(int k, std::vector<std::vector<int>> x) {
int n = x.size();
int m = x[0].size();
if(k==1)
{
vector<pair<int,pair<int,int>>> pos;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
pos.push_back({x[i][j],{i,j}});
}
}
sort(begin(pos),end(pos));
auto ans=x;
ll cost=-1;
{
vector<int> used(n,0);
int l=0;
int r=pos.size();
r--;
vector<vector<int>> cur_ans;
for(int i=0;i<n;i++)
{
cur_ans.push_back({});
for(int j=0;j<m;j++)
{
cur_ans[i].push_back(-1);
}
}
vector<int> cur;
for(int i=0;i<n;i++)
{
if(i%2)
{
while(l<=r)
{
if(!used[pos[r].second.first])
{
int y=pos[r].second.second;
int color=pos[r].second.first;
used[color]=1;
cur_ans[color][y]=0;
cur.push_back(pos[r].first);
break;
}
r--;
}
}
else
{
while(l<=r)
{
if(!used[pos[l].second.first])
{
int y=pos[l].second.second;
int color=pos[l].second.first;
used[color]=1;
cur_ans[color][y]=0;
cur.push_back(pos[l].first);
break;
}
l++;
}
}
}
if(find_ans(cur)>cost)
{
ans=cur_ans;
cost=find_ans(cur);
}
}
{
vector<int> used(n,0);
int l=0;
int r=pos.size();
r--;
vector<vector<int>> cur_ans;
for(int i=0;i<n;i++)
{
cur_ans.push_back({});
for(int j=0;j<m;j++)
{
cur_ans[i].push_back(-1);
}
}
vector<int> cur;
for(int i=0;i<n;i++)
{
if(i<1)
{
while(l<=r)
{
if(!used[pos[r].second.first])
{
int y=pos[r].second.second;
int color=pos[r].second.first;
used[color]=1;
cur_ans[color][y]=0;
cur.push_back(pos[r].first);
break;
}
r--;
}
}
else
{
while(l<=r)
{
if(!used[pos[l].second.first])
{
int y=pos[l].second.second;
int color=pos[l].second.first;
used[color]=1;
cur_ans[color][y]=0;
cur.push_back(pos[l].first);
break;
}
l++;
}
}
}
if(find_ans(cur)>cost)
{
ans=cur_ans;
cost=find_ans(cur);
}
}
{
vector<int> used(n,0);
int l=0;
int r=pos.size();
r--;
vector<vector<int>> cur_ans;
for(int i=0;i<n;i++)
{
cur_ans.push_back({});
for(int j=0;j<m;j++)
{
cur_ans[i].push_back(-1);
}
}
vector<int> cur;
for(int i=0;i<n;i++)
{
if(i<(n/2))
{
while(l<=r)
{
if(!used[pos[r].second.first])
{
int y=pos[r].second.second;
int color=pos[r].second.first;
used[color]=1;
cur_ans[color][y]=0;
cur.push_back(pos[r].first);
break;
}
r--;
}
}
else
{
while(l<=r)
{
if(!used[pos[l].second.first])
{
int y=pos[l].second.second;
int color=pos[l].second.first;
used[color]=1;
cur_ans[color][y]=0;
cur.push_back(pos[l].first);
break;
}
l++;
}
}
}
if(find_ans(cur)>cost)
{
ans=cur_ans;
cost=find_ans(cur);
}
}
{
vector<int> used(n,0);
int l=0;
int r=pos.size();
r--;
vector<vector<int>> cur_ans;
for(int i=0;i<n;i++)
{
cur_ans.push_back({});
for(int j=0;j<m;j++)
{
cur_ans[i].push_back(-1);
}
}
vector<int> cur;
for(int i=0;i<n;i++)
{
if(i>=(n/2))
{
while(l<=r)
{
if(!used[pos[r].second.first])
{
int y=pos[r].second.second;
int color=pos[r].second.first;
used[color]=1;
cur_ans[color][y]=0;
cur.push_back(pos[r].first);
break;
}
r--;
}
}
else
{
while(l<=r)
{
if(!used[pos[l].second.first])
{
int y=pos[l].second.second;
int color=pos[l].second.first;
used[color]=1;
cur_ans[color][y]=0;
cur.push_back(pos[l].first);
break;
}
l++;
}
}
}
if(find_ans(cur)>cost)
{
ans=cur_ans;
cost=find_ans(cur);
}
}
{
vector<int> used(n,0);
int l=0;
int r=pos.size();
r--;
vector<vector<int>> cur_ans;
for(int i=0;i<n;i++)
{
cur_ans.push_back({});
for(int j=0;j<m;j++)
{
cur_ans[i].push_back(-1);
}
}
vector<int> cur;
for(int i=0;i<n;i++)
{
if(i>=1)
{
while(l<=r)
{
if(!used[pos[r].second.first])
{
int y=pos[r].second.second;
int color=pos[r].second.first;
used[color]=1;
cur_ans[color][y]=0;
cur.push_back(pos[r].first);
break;
}
r--;
}
}
else
{
while(l<=r)
{
if(!used[pos[l].second.first])
{
int y=pos[l].second.second;
int color=pos[l].second.first;
used[color]=1;
cur_ans[color][y]=0;
cur.push_back(pos[l].first);
break;
}
l++;
}
}
}
if(find_ans(cur)>cost)
{
ans=cur_ans;
cost=find_ans(cur);
}
}
allocate_tickets(ans);
return cost;
}
else
{
map<int,int> cnt[n];
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cnt[i][x[i][j]]++;
}
}
for(int i=0;i<k;i++)
{
for(int can=(n/2);can>=0;can--)
{
}
}
}
std::vector<std::vector<int>> answer;
for (int i = 0; i < n; i++) {
std::vector<int> row(m);
for (int j = 0; j < m; j++) {
if (j < k) {
row[j] = j;
} else {
row[j] = -1;
}
}
answer.push_back(row);
}
allocate_tickets(answer);
return 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... |