#include "robots.h"
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <set>
#include <queue>
#define endl '\n'
using namespace std;
int x[2000000];
int w[2000000];
int a,t;
bool check(int mid) {
if(w[t-1] >= x[a-1]) return -1;
int ptr=0;
for(int i = 0; i < a; i++) {
int br=1;
if(x[i]<=w[ptr]) continue;
while(ptr<t && x[i]>w[ptr] && br<=mid) {ptr++; br++;}
}
return ptr==t;
}
int putaway(int a, int b, int t, int x[], int y[], int w[], int s[]) {
if(a+b==2 && t==2) {
if(a==0 && b==2) {
if(s[0]<y[0] && s[1]<y[1]) return 1;
else if(s[0]<y[1] && s[1]<y[0]) return 1;
else if(max(s[0], s[1])<max(y[0], y[1])) return 2;
else return -1;
}
else if(a==1 && b==1) {
if(s[0]<y[0] && w[1]<x[0]) return 1;
else if(w[0]<x[0] && s[1]<y[0]) return 1;
else if(max(s[0], s[1])<y[0]) return 2;
else if(max(w[0], w[1])<x[0]) return 2;
else return -1;
}
else if(a==2 && b==0) {
if(w[0]<x[0] && w[1]<x[1]) return 1;
else if(w[0]<x[1] && w[1]<x[0]) return 1;
else if(max(w[0], w[1])<max(x[0], x[1])) return 2;
else return -1;
}
else return -1;
}
if(b==0) {
for(int i = 0; i < t; i++) ::w[i]=w[i];
for(int i = 0; i < a; i++) ::x[i]=x[i];
sort(::w, ::w+t);
sort(::x, ::x+a);
::a=a;
::t=t;
int l = 1, r = t, mid, ans=-1;
while(l<=r) {
mid=(l+r)/2;
if(check(mid)) {
ans = mid;
r = mid - 1;
}
else {
l = mid + 1;
}
}
return ans;
}
return -1;
}