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;
#define ll long long
#define pb push_back
#define F first
#define S second
#define INF 1e18
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define OK cout<<"Ok"<<endl;
#define MOD (ll)(1e9+7)
#define endl "\n"
const int mxn=1e6+5;
int n,a,b;
vector<int>l,r;
vector<pii>arr;
bool check(int k){
priority_queue<int>q;
int idx=0;
for(int i=0;i<a;i++){
while(idx<n&&arr[idx].F<l[i]){
q.push(arr[idx].S);
idx++;
}
int say=min(k,(int)q.size());
while(say--){
q.pop();
}
}
while(idx<n){
q.push(arr[idx].S);
idx++;
}
for(int i=0;i<b;i++){
int say=min((int)q.size(),k);
while(say--){
if(q.top()<r[i]){
q.pop();
}
else{
return false;
}
}
}
if(q.size()) return false;
return true;
}
int putaway(int A, int B, int N, int X[], int Y[], int W[], int S[]) {
n=N;
a=A;
b=B;
for(int i=0;i<a;i++){
l.pb(X[i]);
}
for(int i=0;i<b;i++){
r.pb(Y[i]);
}
for(int i=0;i<n;i++){
arr.pb({W[i],S[i]});
}
sort(all(l));
sort(rall(r));
sort(all(arr));
int l=1,rr=n+1;
while(l<=rr){
int m=(l+rr)/2;
if(check(m)){
rr=m-1;
}
else{
l=m+1;
}
}
rr++;
if(rr>n){
return -1;
}
else{
return rr;
}
}
# | 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... |