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 <algorithm>
#include <cstring>
#include <functional>
#include <iostream>
#include <cassert>
#include <numeric>
#include <set>
using namespace std;
int putaway(int wrobot, int srobot, int n, int rw[], int rs[], int w[], int s[]) {
sort(rw, rw + wrobot);
sort(rs, rs + srobot);
auto comp_w = [&](int i, int j)->bool{ return w[i] < w[j]; };
auto comp_s = [&](int i, int j)->bool{ return s[i] < s[j]; };
int* byw = new int[n];
int* bys = new int[n];
iota(byw, byw + n, 0);
iota(bys, bys + n, 0);
sort(byw, byw + n, comp_w);
sort(bys, bys + n, comp_s);
int* done = new int[n];
auto check = [&](int time)->bool {
memset(done, 0, sizeof(*done)*n);
{
int toy = 0;
set<pair<int,int>> st;
for (int rob = 0; rob < wrobot; rob++) {
while (toy < n && w[byw[toy]] < rw[rob]) {
st.insert({-s[byw[toy]], byw[toy]});
toy++;
}
for (int rem = 0; rem < time && st.size(); rem++) {
done[st.begin()->second] = 1;
st.erase(st.begin());
}
}
}
{
int toy = 0;
set<pair<int,int>> st;
for (int rob = 0; rob < srobot; rob++) {
while (toy < n && s[bys[toy]] < rs[rob]) {
if (!done[bys[toy]])
st.insert({-w[bys[toy]], bys[toy]});
toy++;
}
for (int rem = 0; rem < time && st.size(); rem++) {
done[st.begin()->second] = 1;
st.erase(st.begin());
}
}
}
int all_done = accumulate(done, done + n, 1, bit_and<>());
return all_done;
};
int l = -1, r = n +1;
while (l < r - 1) {
int mid = (l + r) / 2;
if (check(mid)) r = mid;
else l = mid;
}
return r == n+1 ? -1 : r;
}
# | 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... |