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) {
    vector<int> vis(t, 0);
    for (int i : weak) {
        int co = 0;
        for (int j = 0; j < t && co < x; j++) {
            if (vis[j] || toy[j].second >= i) {
                continue;
            }
            vis[j] = 1;
            co++;
        }
    }
    for (int i : small) {
        int co = 0;
        for (int j = 0; j < t && co < x; j++) {
            if (vis[j] || toy[j].first >= i) {
                continue;
            }
            vis[j] = 1;
            co++;
        }
    }
    for (int i = 0; i < t; i++) {
        if (vis[i]) {
            continue;
        }
        return 0;
    }
    return 1;
}
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.begin(), small.end());
    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... |