#include "teams.h"
#include <bits/stdc++.h>
using namespace std;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> bool chmin(T& a, const T&b) {return b < a ? a = b, 1 : 0;}
template<class T> bool chmax(T& a, const T&b) {return a < b ? a = b, 1 : 0;}
#define pb push_back
#define f first
#define s second
#define bg(x) (x).begin()
#define en(x) (x).end()
#define all(x) bg(x), en(x)
#define sz(x) (int((x).size()))
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rev(i, a, b) for (int i = a; i >= b; i--)
const int INF = 1e9+5;
#ifdef LOCAL
#define dbg(x) cout << #x << " = " << x << "\n"
#else
#define dbg(x)
#endif
int n; vi a, b, idx;
void init(int N, int A[], int B[]) {
n = N; a.assign(A, A+N), b.assign(B, B+N);
idx.resize(n); iota(all(idx), 0); sort(all(idx), [&](int i, int j) {return a[i] == a[j] ? b[i] < b[j] : a[i] < a[j];});
}
int m; vi k;
int can(int M, int K[]) {
m = M; k.assign(K, K+m);
sort(all(k));
bool ok = true;
set<pi> avail; int pos = 0;
for (auto v : k) {
while (pos < n && a[idx[pos]] <= v) avail.insert({b[idx[pos]], idx[pos]}), pos++;
int v2 = v;
while (!avail.empty() && v2 > 0) {
auto t = *avail.begin(); avail.erase(t);
if (t.first < v) continue;
v2--;
}
if (v2 > 0) {ok = false; break;}
}
return ok;
}