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;
multiset< pair<int, int> >wt,st;
vector< pair<int,int> >r;
int solve(){
int ans=0;
while(wt.size()>0&&st.size()>0){
ans++;
for(int i=0;i<r.size();i++){
if(!wt.size()&&!st.size()) break;
pair<int,int> x=r[i];
int robot=x.first;
int type=x.second;
//cout<<robot<<"\n";
if(type == 0)
{
auto toy = wt.upper_bound({robot,0});
if(toy == wt.begin()) continue;
toy--;
int wtoy = (*toy).first;
int stoy = (*toy).second;
wt.erase( wt.find( {wtoy,stoy} ) );
st.erase( st.find( {stoy,wtoy} ) );
}
else
{
auto toy=st.upper_bound({robot,0});
if(toy == st.begin()) continue;
toy--;
int wtoy = (*toy).first;
int stoy = (*toy).second;
st.erase(st.find({stoy, wtoy}));
wt.erase(wt.find({wtoy, stoy}));
//cout<<"works\n";
}
//cout<<wt.size()<<"\n";
}
}
return ans;
}
int putaway(int a, int b, int t, int a1[], int b1[], int w[], int s[]) {
sort(a1,a1+a);
sort(b1,b1+b);
int mxa=(a>0 ? a1[a-1]:0),mxb=(b>0 ? b1[b-1]:0);
for(int i=0;i<t;i++){
if(w[i]>=mxa&&s[i]>=mxb) return -1;
wt.insert({w[i],s[i]});
st.insert({s[i],w[i]});
}
for(int i=0;i<a;i++) r.push_back({a1[i],0});
for(int i=0;i<b;i++) r.push_back({b1[i],1});
sort(r.rbegin(),r.rend());
int ans=solve();
return ans;
}
/*
0 2 2
20 10
7 10
13 10
*/
Compilation message (stderr)
robots.cpp: In function 'int solve()':
robots.cpp:12:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
12 | for(int i=0;i<r.size();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... |