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<bits/stdc++.h>
using namespace std;
int n, m, t;
vector<int> weak, small;
vector<pair<int, int>> toy;
bool check(int x) {
    priority_queue<pair<int, int>> pq;
    queue<pair<int, int>> q;
    for (auto c : toy) {
        pq.push(c);
    }
    for (int i : weak) {
        while(!q.empty()) {
            pq.push(q.front());
            q.pop();
        }
        int co = x;
        while(!pq.empty() && co > 0) {
            auto [s, w] = pq.top();
            pq.pop();
            if (w < i) {
                co--;
            } else {
                q.push({s, w});
            }
        } 
    }
    for (int i : small) {
        int co = x;
        while(!pq.empty() && co > 0) {
            auto [s, w] = pq.top();
            pq.pop();
            if (s < i) {
                co--;
            } else {
                return 0;
            }
        }
    }
    if (pq.empty()) {
        return 1;
    } else {
        return 0;
    }
}
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
    n = A, m = B, t = T;
    for (int i = 0; i < t; i++) {
        toy.push_back({S[i], W[i]});
    }
    for (int i = 0; i < n; i++) {
        weak.push_back(X[i]);
    }
    for (int i = 0; i < m; i++) {
        small.push_back(Y[i]);
    }
    int l = 1, r = T;
    sort(toy.rbegin(), toy.rend());
    sort(weak.begin(), weak.end());
    sort(small.rbegin(), small.rend());
    while(l < r) {
        int m = (l+r)/2;
        if (check(m)) {
            r = m;
        } else {
            l = m+1;
        }
    }
    if (check(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... |