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;
const int N = 1e6 + 10;
const int M = 1e5 + 10;
#define pb push_back
int n,a,b;
int _W[N], _S[N];
int _X[N];
int _Y[N];
pair<int,int> _A[N];
bool ok(int mid){
int p = 0;
priority_queue<int> pq;
for(int i = 0;i<a;i++){
while(p < n && _A[p].first < _X[i]){
pq.push(_A[p].second);
p++;
}
int k = mid;
while(pq.size() && k--){
pq.pop();
}
}
while(p < n)pq.push(_A[p++].second);
vector<int> v;
while(pq.size()){
v.pb(pq.top());
pq.pop();
}
for(int i =0 ;i<b;i++){
int k = mid;
while(v.size() && v.back() < _Y[i] && k--){
v.pop_back();
}
}
return v.empty();
}
int putaway(int A, int B, int T, int x[], int y[], int w[], int s[]) {
a = A;
b = B;
n = T;
sort(x, x+a);
sort(y, y + b);
for(int i = 0;i<a;i++){
_X[i] = x[i];
}
for(int i = 0;i<b;i++){
_Y[i] = y[i];
}
for(int i = 0;i<n;i++){
_A[i] = {w[i], s[i]};
}
sort(_A, _A+n);
int lo = 1;
int hi = n;
// int ans = -1;
while(lo <= hi){
int mid = (lo + hi) / 2;
if(ok(mid)){
hi = mid -1;
// ans = mid;
}else lo = mid + 1;
}
if(hi == n)return -1;
return hi + 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... |