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"
//#include "grader.cpp"
using namespace std;
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<int,int>pii;
typedef array<int,4>pi2;
int putaway(int a, int b, int t, int X[], int Y[], int w[], int s[]){
int arr[a];
for(int x=0;x<a;x++) arr[x]=X[x];
int arr2[b];
for(int x=0;x<b;x++) arr2[x]=Y[x];
sort(arr,arr+a);
sort(arr2,arr2+b);
vector<pii>storage[a+5];
vector<int>storage2[b+5];
for(int x=0;x<t;x++){
int index=upper_bound(arr,arr+a,w[x])-arr;
int index2=upper_bound(arr2,arr2+b,s[x])-arr2;
if(index==a&&index2==b) return -1;
storage[index].push_back({index2,x});
storage2[index2].push_back(x);
}
int l=1;
int r=1e6;
int mid;
int best=-1;
while(l<=r){
mid=(l+r)/2;
bool done[t+5];
memset(done,0,sizeof(done));
priority_queue<pii>pq;
for(int x=0;x<a;x++){
for(auto it:storage[x]){
pq.push(it);
}
for(int y=0;y<mid;y++){
if(pq.empty()) break;
pii cur=pq.top();
pq.pop();
done[cur.second]=true;
}
}
int cnt=0;
for(int x=0;x<b;x++){
for(auto it:storage2[x]){
if(done[it]) continue;
cnt++;
}
cnt=max(0,cnt-mid);
}
if(cnt==0){
best=mid;
r=mid-1;
}
else l=mid+1;
}
return best;
}
# | 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... |