1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<pair<int,int>> G;
	vector<pair<int,int>> Q;
	vector<pair<int,int>> zd;
	vector<int> G_nr;
	vector<int> Q_nr;
	int l_pa[n];
	vector<int> l_par[n];
	int l_nzer=0;
	for(int i=0;i<n;i++){
		int a,b,c;
		cin>>a>>b>>c;
		if(a==1){
			G.push_back(make_pair(b,c));
			G_nr.pb(i);
		}
		else{
			Q.pb(mp(b-c,b));
			Q_nr.pb(i);
		}
		l_pa[i]=0;
	}
	for(int i=0;i<G.size();i++){
		for(int j=0;j<Q.size();j++){
			if (G[i].nd+Q[j].nd==G[i].st+(Q[j].nd-Q[j].st)){
				zd.pb(mp(G_nr[i],Q_nr[j]));
			}
		}
	}
	for(int i=0;i<zd.size();i++){
		l_pa[zd[i].st]++;
		l_pa[zd[i].nd]++;
	}
	for(int i=0;i<zd.size();i++){
		l_nzer++;
		if(l_pa[zd[i].st]>=l_pa[zd[i].nd]){
			l_par[zd[i].st].pb(zd[i].nd);
		}
		else{
			l_par[zd[i].nd].pb(zd[i].st);
		}
	}
	sort(l_par,l_par+n,[](vector<int> A, vector<int> B){return A.size()>B.size();});
	for(int i=0;i<n;i++){
		if(l_nzer<=0){
			cout<<i;
			return 0;
		}
		else{
			l_nzer=l_nzer-l_par[i].size();
		}
	}

	
	
	
	
}