# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
588758 | LIF | Carnival Tickets (IOI20_tickets) | C++14 | 453 ms | 73308 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 "tickets.h"
#include <vector>
#include<bits/stdc++.h>
using namespace std;
bool cmp(long long int x,long long int y)
{
return x<y;
}
struct node
{
int least;
int maxn;
long long int val;
int id;
}nod[10005];
bool cmp2(node x,node y)
{
return x.val < y.val;
}
long long find_maximum(int k, std::vector<std::vector<int> > x) {
int mm = x[0].size(); //find the m;
int n = x.size();
vector<vector <int> > s;
long long int a[20005];
long long int sum =0;
if(mm==1)
{
for(int i=0;i<n;i++)
{
vector <int> q;
q.push_back(0);
s.push_back(q);
}
for(int i=0;i<n;i++)
{
a[i] = x[i][0];
}
sort(a,a+n);
long long int ans = a[n/2-1]+a[n/2];
ans /=2;
for(int i=0;i<n;i++)
{
sum += abs(ans - a[i]);
}
allocate_tickets(s);
return sum;
}
if(k==1)
{
for(int i=0;i<n;i++)
{
long long int xx = x[i][0] + x[i][mm-1];
nod[i].val = xx;
nod[i].id = i;
nod[i].least = x[i][0];
nod[i].maxn = x[i][mm-1];
}
sort(nod,nod+n,cmp2); //from small to big
for(int i=0;i<n;i++)
{
vector<int> q;
for(int j=0;j<mm;j++)
{
q.push_back(-1);
}
s.push_back(q);
}
for(int i=0;i<n/2;i++) //it is the range of small
{
int id = nod[i].id;
s[id][0] = 0;
}
for(int i=n/2;i<n;i++)
{
int id = nod[i].id;
s[id][mm-1] = 0;
}
allocate_tickets(s);
for(int i=0;i<n;i++)
{
if(i<n/2)
{
a[i] = nod[i].least;
}
else
{
a[i] = nod[i].maxn;
}
}
sort(a,a+n);
long long int ans = a[n/2] + a[n/2-1];
ans /=2;
for(int i=0;i<n;i++)
{
sum += abs(a[i] - ans);
}
return sum;
}
}
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... |