# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
897968 | Muhammad_Aneeq | 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.
/*
بسم الله الرحمن الرحيم
Author:
(:Muhammad Aneeq:)
*/
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
int const T=1e6+10,N=5e4+10;
pair<int,int>qu[T]={};
int a[N],b[N];
int n,m,t;
bool check(int o)
{
multiset<pair<int,int>>d;
int i=0,j=0;
while (i<n&&j<t)
{
if (a[i]>qu[j].first)
{
d.insert({qu[j].second,j});
j++;
}
else
{
int x=o;
while (min(x,int(d.size())))
{
d.erase(--end(d));
x--;
}
i++;
}
}
while (j<t)
{
d.insert({qu[j].second,j});
j++;
}
j=0;
while (j<m)
{
int x=o;
while (min(x,int(d.size())))
{
if ((*begin(d)).first<b[j])
{
d.erase(begin(d));
x--;
}
else
break;
}
j++;
}
return (d.size()==0);
}
void solve()
{
cin>>n>>m>>t;
for (int i=0;i<n;i++)
cin>>a[i];
for (int i=0;i<m;i++)
cin>>b[i];
sort(a,a+n);
sort(b,b+m);
int am=0,bm=0;
if (n>0)
am=a[n-1];
if (m>0)
bm=b[m-1];
bool w=0;
for (int i=0;i<t;i++)
{
cin>>qu[i].first>>qu[i].second;
if (qu[i].first>=am&&qu[i].second>=bm)
w=1;
}
if (w==1)
{
cout<<-1<<endl;return;
}
sort(qu,qu+t);
int st=0,en=1e6+10;
while(st+1<en)
{
int mid=(st+en)/2;
if (check(mid))
en=mid;
else
st=mid;
}
cout<<en<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
solve();
}