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 <vector>
#include <algorithm>
#include <queue>
using namespace std;
vector<pair<int,int> > U;
priority_queue<int> H;
vector<int> P,Q;
bool chk(int v)
{
int i,j,c;
while (!H.empty()) H.pop();
for (i=j=0;i<P.size();i++){
while (j < U.size() && U[j].first < P[i]){
H.push(U[j].second); j++;
}
c = v;
while (c > 0 && !H.empty()){
H.pop(); c--;
}
}
for (;j<U.size();j++) H.push(U[j].second);
for (i=0;i<Q.size();i++){
c = v;
while (c > 0 && !H.empty()){
if (H.top() >= Q[i]) return false;
H.pop(); c--;
}
if (H.empty()) break;
}
return H.empty();
}
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
int i,x=0,y=0;
for (i=0;i<A;i++){
P.push_back(X[i]);
x = max(x,X[i]);
}
sort(P.begin(),P.end());
for (i=0;i<B;i++){
Q.push_back(Y[i]);
y = max(y,Y[i]);
}
sort(Q.rbegin(),Q.rend());
for (i=0;i<T;i++){
if (W[i] >= x && S[i] >= y) return -1;
U.push_back(make_pair(W[i],S[i]));
}
sort(U.begin(),U.end());
int l = 1, r = T, m = 1;
while (l < r){
m = (l + r) / 2;
if (chk(m)) r = m - 1;
else l = m + 1;
}
while (chk(m)) m--;
while (!chk(m)) m++;
return m;
}
# | 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... |