#include "teams.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
const ll LOG = 31;
const ll MOD = 1000000007;
const ll inf = 1e17;
#define db(x) cerr << #x << " = " << x << " | "
#define dbg(x) cerr << #x << " = " << x << "\n"
vector<pll> v;
ll n;
void init(int N, int a[], int b[]) {
n = N;
for (ll i = 0; i < n; i++) {
v.push_back({a[i], b[i]});
}
sort(v.begin(), v.end());
}
int can(int m, int k[]) {
sort(k, k + m);
multiset<ll> act;
ll x = 0;
for (ll i = 0; i < m; i++) {
while (x < n && v[x].first <= k[i]) {
act.insert(v[x].second);
x++;
}
ll c = k[i];
while (c--) {
auto it = act.lower_bound(k[i]);
if (it == act.end()) return 0;
act.erase(it);
}
}
return 1;
}