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;
int n,m,k;
int a[50005], b[50005];
pair<int,int> p[1000005];
priority_queue<pair<int,int> > heap;
bool check(int cnt) {
int i,j,cur;
j = 0;
while(!heap.empty()) heap.pop();
for(i=0;i<n;i++) {
while(j<k && p[j].second<a[i]) heap.push(p[j++]);
for(cur=0;cur<cnt && !heap.empty();cur++) heap.pop();
}
while(j<k) heap.push(p[j++]);
for(i=m-1;i>=0;i--) {
for(cur=0;cur<cnt && !heap.empty();cur++) {
if(heap.top().first>=b[i]) return 0;
if(!heap.empty()) heap.pop();
}
}
return heap.empty();
}
bool cmp(pair<int,int> x,pair<int,int> y) {
return x.second<y.second;
}
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
int i,l,r,mid,ans;
n = A; m = B; k = T;
for(i=0;i<n;i++) a[i] = X[i];
for(i=0;i<m;i++) b[i] = Y[i];
for(i=0;i<k;i++) p[i] = {S[i],W[i]};
sort(&a[0],&a[n]);
sort(&b[0],&b[m]);
sort(&p[0],&p[k],cmp);
l = 1; r = k; ans = -1;
while(l<=r) {
mid = (l+r)/2;
if(check(mid)) {
ans = mid;
r = mid-1;
}
else l = mid+1;
}
return ans;
}
# | 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... |