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 "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
vector <pair <int,int> > toy;
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
sort(X, X+A);
sort(Y, Y+B);
if(A==0){
swap(X,Y);
swap(W,S);
swap(A,B);
}
toy.resize(T);
for(int i = 0 ; i < T ; i++){
toy[i].first = W[i];
toy[i].second = S[i];
if(W[i]>= X[A-1] && S[i]>=Y[B-1])
return -1;
}
sort(toy.begin(), toy.end() );
if(B==0){
if(X[A-1] <= toy[T-1].first )
return -1;
int res = (T + A -1 )/ A;
for(int i = 0; i < A - 1 ;i++){
if( X[i] <= toy[0].first){
res = max ( res, (T + ( A - i- 1) -1 )/ (A - i -1 ));
}
int ind = upper_bound(toy.begin(), toy.end(), make_pair (X[i], 2000000002)) - toy.begin() ;
res = max ( res, (T - ind + (A-i-1) - 1) / ( A - i - 1));
}
return res;
}
int l = 1, r = T;
int ans = T;
while(r - l > 0){
int mid = (l + r) / 2;
deque <int > vec;
int cnt = 0;
for(int i = 0 ; i < A ; i++){
int sz = 0;
while( cnt < T && X[i] > toy[cnt].first){
vec.push_back(toy[cnt].second);
cnt++;
}
if(vec.size() <= mid){
vec.clear();
}
else
{
sort(vec.begin(), vec.end());
reverse(vec.begin(), vec.end());
sz = min(int(vec.size()), mid);
if(sz!=0)
vec.erase(vec.begin(), vec.begin() + sz);
}
if(i==A-1){
while(cnt < T){
vec.push_back(toy[cnt].second);
cnt++;
}
}
}
sort(vec.begin(), vec.end());
for(int i = 0 ; i < B; i++){
int sz =0;
if(vec.size() >=mid && vec[mid-1] < Y[i]){
vec.erase(vec.begin(), vec.begin() + mid );
continue;
}
while(vec.size()> 0 && sz < mid && vec[0]< Y[i] ){
vec.erase(vec.begin());
sz++;
}
}
if(vec.size()==0 ){
r = mid;
ans = mid;
}
else{
l = mid + 1;
}
}
return ans;
}
/*
3 2 10
6 2 9
4 7
4 6
8 5
2 3
7 9
1 8
5 1
3 3
8 7
7 6
10 5
*/
Compilation message (stderr)
robots.cpp: In function 'int putaway(int, int, int, int*, int*, int*, int*)':
robots.cpp:50:27: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
50 | if(vec.size() <= mid){
| ~~~~~~~~~~~^~~~~~
robots.cpp:74:27: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
74 | if(vec.size() >=mid && vec[mid-1] < Y[i]){
| ~~~~~~~~~~~^~~~~
# | 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... |