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;
#define pb push_back
#define f1 first
#define s2 second
using ii = pair<int, int>;
const int MAX = 5e4 + 69;
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[])
{
if (A > B)
swap(A, B), swap(X, Y), swap(W, S);
sort(X, X+A);
sort(Y, Y+B);
for (int i = 0; i < T; ++i)
{
if ((A == 0 || X[A-1] <= W[i]) && (B == 0 || Y[B-1] <= S[i]))
return -1;
}
vector<ii> vec;
for (int i = 0; i < T; ++i)
{
int p = (int)(upper_bound(X, X+A, W[i]) - X);
int q = (int)(upper_bound(Y, Y+B, S[i]) - Y);
vec.pb({p, q});
}
sort(vec.rbegin(), vec.rend());
int ar[MAX];
const auto check = [&](int val) -> bool
{
for (int i = 0; i <= B; ++i)
ar[i] = 0;
for (int i = 0, ctr = 0; i < T; ++i)
{
if (ctr < 1ll * (A - vec[i].f1) * val)
ctr++;
else ar[0]++, ar[vec[i].s2 + 1]--;
}
for (int i = 1; i <= B; ++i)
ar[i] += ar[i-1];
for (int i = 0; i <= B; ++i)
if (ar[i] > 1ll * (B-i) * val)
return false;
return true;
};
int l = 1, r = T;
while (l < r)
{
int mid = (l + r) >> 1;
if (check(mid)) r = mid;
else l = mid + 1;
}
return l;
}
# | 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... |