# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1002613 | hasan2006 | 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>
//#include "robots.h"
using namespace std;
#define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define rall(s) s.rbegin(),s.rend()
#define all(s) s.begin(),s.end()
#define pb push_back
#define se second
#define fi first
#define ll long long
#define ld long double
#define YES cout<<"YES\n"
#define Yes cout<<"Yes\n"
#define yes cout<<"yes\n"
#define NO cout<<"NO\n"
#define No cout<<"No\n"
#define no cout<<"no\n"
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
ll i , j , l ,r , s = 0 , f , x , y , k , n, m , ans = 0;
sort(X , X + A);
sort(Y , Y + B);
vector<pair<int,int>>v;
for(i = 0; i < T; i++){
v.pb({W[i] , S[i]});
if(A > 0 && X[A - 1] > W[i])
continue;
if(B > 0 && Y[B - 1] > S[i])
continue;
return -1;
}
sort(all(v));
l = T / (A + B);
r = T;
while(l != r){
m = (l + r) / 2;
ll R = 0;
multiset<pair<int,int>>st;
for(i = 0; i < A; i++){
while(R < v.size() && v[R].fi < X[i])
st.insert({v[R].se , v[R].fi}),R++;
y = m;
while((y--) && st.size()){
st.erase(st.find({st.rbegin()->fi , st.rbegin()->se}));
}
}
for(i = R; i < v.size(); i++)
st.insert({v[i].se, v[i].fi});
for(i = 0; i < B; i++){
y = m;
while((y--) && st.size() && st.begin()->fi < Y[i])
st.erase(st.begin());
}
if(st.size())
l = m + 1;
else
r = m;
}
return l;
}
/*
int main(){
TL;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int a[] = {6 , 2 , 9};
int b[] = {4 , 7};
int c[] = {4 , 8 , 2 , 7 , 1 , 5 , 3 ,8 , 7 , 10};
int d[] = {6 , 5 , 3 , 9 , 8, 1 , 3 , 7 , 6 , 5};
cout<<putaway(3 , 2 , 10 , a , b , c , d )<<"\n";
}*/
// Author : حسن