# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1078972 | Muhammad_Aneeq | Carnival Tickets (IOI20_tickets) | C++17 | 1 ms | 860 KiB |
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 <vector>
#include <set>
#include <deque>
#include <algorithm>
#include <iostream>
using namespace std;
void allocate_tickets( vector<vector<int>> _x);
long long find_maximum(int k, vector<vector<int>> d)
{
int n=d.size(),m=d[0].size();
if (m==1)
{
vector<vector<int>>ans=d;
vector<int>f;
for (int i=0;i<n;i++)
{
ans[i][0]=0;
f.push_back(d[i][0]);
}
allocate_tickets(ans);
sort(begin(f),end(f));
long long z=0;
for (int i=0;i<n;i++)
z+=abs(f[i]-f[n/2]);
return z;
}
if (k==1)
{
long long z=0;
vector<int>ind(vector<int>(n,0));
vector<vector<int>>ans(n,vector<int>(m,-1));
for (int i=0;i<n;i++)
{
for (int j=0;j<m;j++)
{
set<pair<int,int>>s;
for (int l=0;l<n;l++)
{
if (l==i)
continue;
if (d[l][0]<=d[i][j])
{
int f=d[i][j]-d[l][0]-abs(d[l].back()-d[i][j]);
s.insert({f,l});
}
}
set<pair<int,int>>s1;
for (int l=0;l<n;l++)
{
if (l==i)
continue;
if (d[i][j]<=d[l].back())
s1.insert({d[l].back()-d[i][j],l});
}
if (s.size()<n/2-1)
continue;
if (s1.size()<n/2-1)
break;
long long val=0;
vector<int>mi,ma;
for (int l=0;l<n/2-2;l++)
{
int in=(*rbegin(s)).second;
mi.push_back(in);
s.erase(*rbegin(s));
s1.erase({d[in].back()-d[i][j],in});
val+=d[i][j]-d[in][0];
}
for (int l=0;l<2;l++)
{
if (s.size()==0)
break;
int in=(*rbegin(s)).second;
mi.push_back(in);
s.erase(*rbegin(s));
s1.erase({d[in].back()-d[i][j],in});
val+=d[i][j]-d[in][0];
if (s1.size()<n/2-l)
continue;
auto en=rend(s1);
long long er=val;
ma={};
for (int u=0;u<n/2-l;u++)
{
int in=(*en).second;
ma.push_back(in);
er+=(*en).first;
en--;
}
if (er>z)
{
ind.resize(n,0);
z=er;
for (auto l:mi)
ind[l]=0;
for (auto l:ma)
ind[l]=m-1;
ind[i]=j;
}
}
}
}
for (int i=0;i<n;i++)
ans[i][ind[i]]=0;
allocate_tickets(ans);
return z;
}
return 0;
}
Compilation message (stderr)
# | 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... |