#include "robots.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+10;
int x[maxn], y[maxn];
vector<pair<int,int>>v;
bool check(int at, int a, int b, int n){
    priority_queue<int>pq;
    int id=0;
    for(int i=1;i<=a;i++){
        while(id<v.size()&&v[id].first<x[i]){
            pq.push(v[id].second);
            id++;
        }
        int qtd=at;
        while(qtd&&pq.size()){
            qtd--;
            pq.pop();
        }
    }
    while(id<v.size()){
        pq.push(v[id].second);
        id++;
    }
    for(int i=1;i<=b;i++){
        if(!pq.size()) break;
        int aux=pq.top();
        if(aux>=y[i]) return false;
        for(int j=1;j<=at;j++) if(pq.size()) pq.pop();
    }
    if(pq.size()) return false;
    else return true;
}
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]){
    int l=1, r=T;
    for(int i=1;i<=A;i++) x[i]=X[i-1];
    for(int i=1;i<=B;i++) y[i]=-Y[i-1];
    for(int i=1;i<=T;i++) v.push_back({W[i-1],S[i-1]});
    sort(v.begin(),v.end());
    sort(x+1,x+1+A); sort(y+1,y+1+B);
    for(int i=1;i<=B;i++) y[i]=-y[i];
    while(l<r){
        int mid=(l+r)/2;
        if(check(mid,A,B,T)) r=mid;
        else l=mid+1;
    }
    if(check(l,A,B,T)) 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... |