# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
384980 | Ahmadsm2005 | Carnival Tickets (IOI20_tickets) | C++14 | 3 ms | 748 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 <bits/stdc++.h>
//#include "grader.cpp"
#include "tickets.h"
using namespace std;
long long find_maximum(int k,vector<vector<int>> x) {
int n = x.size();
long long CNT=0;
int m = x[0].size();
vector<vector<int>>answer(n);
for(int i=0;i<n;i++)
for(int l=0;l<m;l++)
answer[i].push_back(-1);
set<pair<int,pair<int,int>>>lol;
set<int>VIS;
vector<pair<int,pair<int,int>>>TEMP,TEMP2;
for(int i=0;i<n;i++){
for(int l=0;l<m;l++){
lol.insert({x[i][l],{i,l}});
}
}
int Z=0;
int N=n;
while(N){
auto itr=lol.end(),itr2=lol.begin();
itr--;
while(VIS.find((itr->second).first)!=VIS.end())
itr--;
VIS.insert((itr->second).first);
while(VIS.find((itr2->second).first)!=VIS.end())
itr2++;
int DIFF=((itr->first)-(itr2->first));
VIS.erase((itr->second).first);
itr=lol.end(),itr2=lol.begin();
itr--;
while(VIS.find((itr2->second).first)!=VIS.end())
itr2++;
VIS.insert((itr2->second).first);
while(VIS.find((itr->second).first)!=VIS.end())
itr--;
bool YAY=0;
if(((itr->first)-(itr2->first))>DIFF){
YAY=1;
}
else{
VIS.erase((itr2->second).first);
itr=lol.end(),itr2=lol.begin();
itr--;
while(VIS.find((itr->second).first)!=VIS.end())
itr--;
VIS.insert((itr->second).first);
while(VIS.find((itr2->second).first)!=VIS.end())
itr2++;
}
TEMP.push_back({(itr->first),{(itr->second).first,(itr->second).second}});
TEMP.push_back({(itr2->first),{(itr2->second).first,(itr2->second).second}});
if(YAY)
VIS.insert((itr->second).first);
else
VIS.erase((itr2->second).first);
lol.erase(itr),lol.erase(itr2);
N-=2;
}
Z++;
sort(TEMP.begin(),TEMP.end());
int X=TEMP[(TEMP.size()-1)/2].first;
for(int i=0;i<TEMP.size();i++){
CNT+=abs(TEMP[i].first-X);
}
for(int i=0;i<TEMP.size();i++)
answer[TEMP[i].second.first][TEMP[i].second.second]=0;
long long MAXER=CNT;
allocate_tickets(answer);
return MAXER;
}
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... |