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<set>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<iostream>
using namespace std;
vector<pair<int,int> > v;
multiset<int> se;
int a,b,t,x[2000000],y[2000000],w[2000000],s[2000000];
int kar(int p)
{
    if(b>0)
    {
        se.clear();
        for(int i=0;i<t+b;i++)
    {
        int f=v[i].second;
        if(f==-1)
        {
            int u=0;
            set<int>::iterator it;
            while(se.size()>0 && u<p)
            {
                u++;
                it=se.end();
                it--;
                se.erase(it);
            }
        }
        else
            se.insert(f);
    }
    for(int i=0;i<a;i++)
    {
        int u=0;
        while(se.size()>0 && (*se.begin())<x[i] && u<p)
        {
            se.erase(se.begin());
            u++;
        }
    }
    if(se.size()==0)
        return 1;
    else
        return 0;
    }
    else
    {
        int h=0;
        for(int i=0;i<a;i++)
        {
            int u=0;
            while(h<t && u<p && w[h]<x[i])
            {
                h++;
                u++;
            }
        }
        if(h==t)
            return 1;
        else
            return 0;
    }
}
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
    for(int i=0;i<B;i++)
        y[i]=Y[i];
    for(int i=0;i<A;i++)
        x[i]=X[i];
    for(int i=0;i<T;i++)
        w[i]=W[i];
    a=A;
    b=B;
    t=T;
    sort(x,x+a);
    sort(y,y+b);
    sort(w,w+t);
    for(int i=0;i<T;i++)
        v.push_back(make_pair(S[i],W[i]));
    for(int i=0;i<b;i++)
        v.push_back(make_pair(y[i],-1));
    sort(v.begin(),v.end());
    int l=T/(A+B),r=min(300,T);
    while(l!=r && l<r)
    {
        int mid=(l+r)/2;
        if(kar(mid))
            r=mid;
        else
            l=mid+1;
    }
    if(kar(l))
        return l;
    else
    {
        l=301;r=T;
        while(l!=r && l<r)
        {
            int mid=(l+r)/2;
            if(kar(mid))
                r=mid;
            else
                l=mid+1;
        }
        if(kar(l))
            return l;
        else
            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... |