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 <bits/stdc++.h>
#include "robots.h"
using namespace std;
bool Test(int x, int A, int B, int T, const vector<int> &X, const vector<int> &Y, const vector<pair<int, int>> &Toy)
{
vector<pair<int, int>> sweep; //weight, id
for (int i = 0; i < T; i++) sweep.emplace_back(Toy[i].first, i);
for (int i = 0; i < A; i++) sweep.emplace_back(X[i], -1);
sort(sweep.begin(), sweep.end());
multiset<int> remain;
for (auto [w, id] : sweep)
{
if (id == -1)
{
int remov = x;
while (remov > 0 && !remain.empty()) remain.erase(prev(remain.end())), --remov;
}
else remain.insert(Toy[id].second);
}
sweep.clear();
for (auto x : remain) sweep.emplace_back(x, 1);
for (int i = 0; i < B; i++) sweep.emplace_back(Y[i], -1);
sort(sweep.begin(), sweep.end());
int cnt = 0;
for (auto [s, type] : sweep)
{
if (type == -1) cnt = max(0, cnt-x);
else cnt++;
}
return (cnt == 0);
}
int putaway(int A, int B, int T, int _X[], int _Y[], int _W[], int _S[])
{
vector<int> X(A), Y(B);
vector<pair<int, int>> Toy(T);
for (int i = 0; i < A; i++) X[i] = _X[i];
for (int i = 0; i < B; i++) Y[i] = _Y[i];
for (int i = 0; i < T; i++) Toy[i] = make_pair(_W[i], _S[i]);
sort(X.begin(), X.end()); sort(Y.begin(), Y.end());
for (int i = 0; i < T; i++) if (Toy[i].first >= X.back() && Toy[i].second >= Y.back()) return -1;
sort(Toy.begin(), Toy.end());
int ini = 0, fim = T;
while (ini < fim)
{
int m = (ini + fim) >> 1;
if (Test(m, A, B, T, X, Y, Toy)) fim = m;
else ini = m+1;
}
return fim;
}
# | 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... |