This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
- Binary search for the answer, and greedily check if we can collect all the items in the given amount of seconds.
- The check can be done in T*log T so the total complexity is T*log^2 T
*/
#include <bits/stdc++.h>
#include "robots.h"
#define pb push_back
using namespace std;
pair<int,int> maxx=make_pair(INT_MAX,INT_MAX);
int putaway(int a, int b, int t, int x[], int y[], int W[], int S[]) {
sort(x,x+a);
sort(y,y+b);
reverse(y,y+b);
vector<pair<int,int> > items(t);
for(int i=0;i<t;i++)
{
items[i].first=W[i];
items[i].second=S[i];
}
items.pb(maxx);
sort(items.begin(),items.end());
int l=1,r=t+5;
while(l<r)
{
int mid=(l+r)/2;
int j=0;
int test=true;
priority_queue<int> s;
for(int i=0;i<a;i++)
{
while(items[j].first<x[i])
{
s.push(items[j].second);
j++;
}
for(int k=0;k<mid;k++)
{
if(s.empty())
break;
s.pop();
}
}
for(;j<t;j++)
s.push(items[j].second);
for(int i=0;i<b;i++)
{
for(int k=0;k<mid;k++)
{
if(s.size()==0)
{
break;
break;
}
if((s.top())<y[i])
s.pop();
else
{
break;
break;
}
}
}
if(s.size()!=0)
test=false;
if(test)
{
r=mid;
}
else
{
l=mid+1;
}
}
if(l==t+5)
return -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... |