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;
using pii = pair<int, int>;
#define F first
#define S second
int A, B, T, *X, *Y;
vector<pii> toys;
bool check(int lim)
{
priority_queue<int> Q;
int j = 0;
for (int i = 0; i < A; ++i) {
while (j < T && toys[j].F < X[i])
Q.emplace(toys[j++].S);
for (int c = 0; c < lim && !Q.empty(); ++c)
Q.pop();
}
while (j < T) Q.emplace(toys[j++].S);
for (int i = B-1; i >= 0; --i) {
if (!Q.empty() && Q.top() >= Y[i]) return false;
for (int c = 0; c < lim && !Q.empty(); ++c)
Q.pop();
}
return Q.empty();
}
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[])
{
::A = A, ::B = B, ::T = T, ::X = X, ::Y = Y;
sort(X, X+A);
sort(Y, Y+B);
//toys.reserve(T);
for (int i = 0; i < T; ++i)
toys.emplace_back(W[i], S[i]);
sort(toys.begin(), toys.end());
int b = 1;
int e = T+1;
while (b < e) {
int m = (b+e)/2;
if (check(m)) e = m;
else b = m+1;
}
return b == T+1 ? -1 : b;
}
# | 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... |