#include "teams.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100;
int n;
int l[MAXN], r[MAXN];
void init(int N, int a[], int b[]) {
	n = N;
	for (int i=0; i<n; i++) {
		l[i] = a[i]; r[i] = b[i];
	}
}
set<int> adjA[MAXN], adjB[MAXN];
set<int> matchB[MAXN];
int matchA[MAXN];
bool visA[MAXN];
bool dfs(int j) {
	// cout << j << endl;
	for (int i : adjB[j]) {
		if (visA[i]) continue;
		visA[i] = true;
		if (matchA[i] == -1) {
			adjB[j].erase(i);
			matchB[j].insert(i);
			adjA[i].erase(j);
			matchA[i] = j;
			return true;
		}
		if (dfs(matchA[i])) {
			adjA[i].insert(matchA[i]);
			adjB[matchA[i]].insert(i);
			matchB[matchA[i]].erase(i);
			matchA[i] = j;
			
			adjA[i].erase(j);
			adjB[j].erase(i);
			matchB[j].insert(i);
			return true;
		}
	}
	return false;
}
int can(int m, int k[]) {
	// clear cache
	for (int i=0; i<n; i++) {
		adjA[i].clear();
		matchA[i] = -1;
	}
	for (int i=0; i<m; i++) {
		adjB[i].clear();
		matchB[i].clear();
	}
	sort(k, k+m);
	for (int i=0; i<n; i++) {
		for (int j=0; j<m; j++) {
			if (l[i] <= k[j] and k[j] <= r[i]) {
				adjA[i].insert(j);
				adjB[j].insert(i);
			}
		}
	}
	for (int j=0; j<m; j++) {
		vector<int> topair;
		for (int viz : adjB[j]) {
			if (matchA[viz] == -1 and (int)matchB[j].size() < k[j]) {
				matchA[viz] = j;
				matchB[j].insert(viz);
				topair.push_back(viz);
			}
		}
		for (int viz : topair) {
				adjB[j].erase(viz);
				adjA[viz].erase(j);
		}
	}
	bool can = true;
	for (int j=0; j<m and can; j++) {
		// cout << j << ' ' << k[j] << ' ' << (int)matchB[j].size() << endl;
		while ((int)matchB[j].size() < k[j] and can) {
			for (int i=0; i<n; i++) visA[i] = false;
			if (!dfs(j)) can = false;
			// else cout << "relaxed" << ' ' << k[j] << ' ' << (int)matchB[j].size() << endl;
		}
	}
	// cout << endl;
	if (!can) return 0;
	return 1;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |