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;
pair<long long, long long> toy[1000005];
priority_queue<long long> pq;
vector<long long> vec;
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[])
{
sort(X, X+A);
sort(Y, Y+B);
for (long long i=0; i<T; i++)
{
if ((!A || W[i]>=X[A-1]) && (!B || S[i]>=Y[B-1]))
return -1;
long long ind=upper_bound(X, X+A, W[i])-X, jnd=upper_bound(Y, Y+B, S[i])-Y;
toy[i]={ind, jnd};
}
sort(toy, toy+T);
long long l=1, r=T;
while (l<r)
{
long long mid=(l+r)/2, ind=0, jnd=0, num=0, sz=0;
for (long long i=0; i<A; i++)
{
while (ind<T && toy[ind].first<=i)
{
pq.push(toy[ind].second);
ind++;
}
long long cnt=mid;
while (!pq.empty() && cnt)
{
pq.pop();
cnt--;
}
}
while (ind<T)
{
pq.push(toy[ind].second);
ind++;
}
vec.clear();
while (!pq.empty())
{
vec.push_back(pq.top());
pq.pop();
sz++;
}
reverse(vec.begin(), vec.end());
bool ok=1;
for (long long i=0; i<sz; i++)
{
if (jnd==B)
{
ok=0;
break;
}
if (jnd<vec[i])
{
jnd=vec[i];
num=0;
}
num++;
if (num==mid)
{
jnd++;
num=0;
}
}
if (ok)
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... |