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;
vector<pair<int,int>>v;
int mid;
bool slv(deque<int>dq){
map<pair<int,int>,int>mp;
priority_queue<pair<int,int>>pq;
int l=0;
for(int i=0;i<dq.size();i++){
while(l<v.size()&&dq[i]>v[l].first){
pq.push({v[l].second,v[l].first});
l++;
}
int k=mid;
while(pq.size()&&k--){
mp[{pq.top().second,pq.top().first}]++;
pq.pop();
}
}
vector<pair<int,int>>vec;
for(auto &i:v){
if(mp[i]){
mp[i]--;
}else vec.push_back(i);
}
v=vec;
return vec.empty();
}
int putaway(int A, int B, int t, int x[], int y[], int w[], int s[]) {
for(int i=0;i<t;i++)v.push_back({w[i],s[i]});
deque<int>a,b;
for(int i=0;i<A;i++)a.push_back(x[i]);
for(int i=0;i<B;i++)b.push_back(y[i]);
sort(a.begin(),a.end());
sort(b.begin(),b.end());
int l=0,r=t,f=-1;
vector<pair<int,int>>vec=v;
while(l<=r){
mid=(l+r)/2;
v=vec;
sort(v.begin(),v.end());
slv(a);
for(auto &i:v)swap(i.first,i.second);
sort(v.begin(),v.end());
bool bl=slv(b);
for(auto &i:v)swap(i.first,i.second);
if(bl){
r=mid-1;
f=mid;
}else l=mid+1;
}
return f;
}
Compilation message (stderr)
robots.cpp: In function 'bool slv(std::deque<int>)':
robots.cpp:10:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
10 | for(int i=0;i<dq.size();i++){
| ~^~~~~~~~~~
robots.cpp:11:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
11 | while(l<v.size()&&dq[i]>v[l].first){
| ~^~~~~~~~~
# | 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... |