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
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> s[2];

int main() {
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	for (int i=0;i<n;i++) {
		int r,w,t;
		cin >> r >> w >> t;
		s[r-1].push_back(w-t);
	}
	sort(s[0].begin(), s[0].end());
	sort(s[1].begin(), s[1].end());
	//for (int i=0;i<s[0].size();i++) cout << s[1][i] << " ";cout << endl;
	int i=0,j=0;
	int k=0;
	while (i<s[0].size() && j<s[1].size()) {
		if (s[0][i]<s[1][j])
			i++;
		else if (s[0][i]>s[1][j])
			j++;
		else {
			k++;
			i++;
			j++;
		}
	}
	cout << k;
	return 0;
}