# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
931278 | AlphaMale06 | Robots (IOI13_robots) | C++17 | 0 ms | 0 KiB |
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>
#define F first
#define S second
#define pb push_back
using namespace std;
int putaway(int n, int m, int S, int a[], int b[], int w[], int s[]) {
pair<int, int> p[S];
for(int i=0; i< S; i++)p[i]={w[i], s[i]};
sort(p, p+S);
sort(a, a+n);
sort(b, b+m);
for(int i=0; i< n; i++)a[i]--;
for(int i=0; i< m; i++)b[i]--;
int ans=1e9;
int l=0, r = S;
while(l<=r){
int s=l+r>>1;
multiset<int> st;
int pt=0;
for(int i=0; i< n; i++){
while(pt<S && p[pt].F<=a[i]){
st.insert(p[pt].S);
pt++;
}
if(st.size()<=s){
st.clear();
continue;
}
for(int j=0; j<s; j++){
st.erase(st.find((*st.rbegin())));
}
}
while(pt<S){
st.insert(p[pt].S);
pt++;
}
vector<int> v;
for(auto p : st)v.pb(p);
for(int i = m-1; i>=0; i--){
for(int j=0; j<s; j++){
if(v.size()){
if(v.back()<=b[i]){
v.pop_back();
}
else break;
}
else break;
}
}
if(v.size()){
l=s+1;
}
else{
r=s-1;
ans=s;
}
}
if(ans==1e9)return -1;
return ans;
}