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 "robots.h"
#include <map>
#include <vector>
#include <algorithm>
#include <array>
const int INF=2e9+7;
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
int low=0,high=T+1;
while(high-low>1){
int mid=(low+high)/2;
std::vector<std::array<int,3> > objects;
for(int i=0;i<A;i++){
objects.push_back({X[i]-1,INF,mid});
}
for(int i=0;i<B;i++){
objects.push_back({INF,Y[i]-1,mid});
}
for(int i=0;i<T;i++){
objects.push_back({W[i],S[i],-1});
}
std::sort(objects.begin(),objects.end());
std::reverse(objects.begin(),objects.end());
std::map<int,int> active;
bool bad=false;
for(auto obj:objects){
if(obj[2]>0){
active[obj[1]]+=obj[2];
}else{
auto it=active.lower_bound(obj[1]);
if(it==active.end()){
bad=true;
break;
}else{
//printf("(%d,%d) matches with (?,%d)\n",obj[0],obj[1],it->first);
if(--it->second==0){
active.erase(it);
}
}
}
}
if(bad){
low=mid;
}else{
high=mid;
}
}
return (high<=T)?high:-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... |