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
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> Vals[2];

int main()
{
	int n;
	cin >> n;
	for (int i = 0;i < n;i++) {
		int a, b, c;
		cin >> a >> b >> c;
		Vals[a - 1].push_back(b - c);
	}
	
	sort(Vals[0].begin(), Vals[0].end());
	sort(Vals[1].begin(), Vals[1].end());

	vector<int>::iterator it[2];
	it[0] = Vals[0].begin();
	it[1] = Vals[1].begin();

	int acc = 0;

	while (it[0] != Vals[0].end() && it[1] != Vals[1].end())
	{
		if((*it[0]) < (*it[1])){
			it[0]++;
			continue;
		}

		if ((*it[0]) > (*it[1])) {
			it[1]++;
			continue;
		}

		int referenceVal = (*it[0]);
		int count[2] = { 0 };
		for (int i = 0;i < 2;i++) {
			while (it[i] != Vals[i].end() && (*it[i]) == referenceVal)
			{
				count[i]++;
				it[i]++;
			}
		}

		if (count[0] < count[1])
			acc += count[0];
		else
			acc += count[1];
		
	}

	cout << acc;

	return 0;
}