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

using namespace std;
using PII = pair<int, int>;

int main()
{
	int n, r, w, t;

	cin >> n;

	vector<PII> cars;

	for (int i = 0; i < n; ++i)
	{
		cin >> r >> w >> t;

		cars.push_back(make_pair(w - t, r));
	}

	cars.push_back(make_pair(10000000, 1));

	sort(cars.begin(), cars.end());

	int res = 0;
	int cur = -10000000;
	int cnt1 = 0;
	int cnt2 = 0;

	for (int i = 0; i < cars.size(); ++i)
	{
		if (cars[i].first != cur)
		{
			res += min(cnt1, cnt2);

			cur = cars[i].first;
			cnt1 = 0;
			cnt2 = 0;
		}
		
		if (cars[i].second == 1)
			++cnt1;
		else
			++cnt2;
	}

	cout << res << endl;

	return 0;
}