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"
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define SZ(x) ((int) (x).size())
using namespace std;
vector<pii> v;
int A, B, *x, *y;
bool check(int t){
priority_queue<int, vector<int>> pq;
int j = 0;
for(int i = 0; i < A; i++){
while(j < SZ(v) && v[j].ff < x[i]){
pq.push(v[j++].ss);
}
int k = t;
while(!pq.empty() && k > 0){
k--;
pq.pop();
}
}
while(j < SZ(v)){
pq.push(v[j++].ss);
}
for(int i = B-1; i >= 0; i--){
int k = t;
while(!pq.empty() && k > 0 && pq.top() < y[i]){
k--;
pq.pop();
}
}
return (pq.empty());
}
int bs(int l, int r){
while(r - l > 1){
int m = (l + r) / 2;
if(check(m)){
r = m;
} else{
l = m;
}
}
return r;
}
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]){
int mxw = *max_element(X, X+A);
int mxs = *max_element(Y, Y+B);
for(int i = 0; i < T; i++){
if(A > 0 && W[i] < mxw){
continue;
} else if(B > 0 && S[i] < mxs){
continue;
} else{
return -1;
}
}
::A = A, ::B = B;
x = X, y = Y;
for(int i = 0; i < T; i++){
v.pb({W[i], S[i]});
}
sort(v.begin(), v.end());
sort(x, x+A);
sort(y, y+B);
return bs(0, T+1);
}
# | 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... |