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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	long long a;
	long long b;
	long long t;
	long long ilo;
	long long odwolania=0;
	long long j = 0;
	vector<long long>x;
	vector<long long>y;
	cin >> ilo;
	for (long long i = 0; i < ilo; i++)
	{
		cin >> a >> b >> t;
		if (a == 1)
			x.push_back(b - t);
		else
			y.push_back(b - t);
	}
	if((x.size()==0)||(y.size()==0))
		odwolania = 0;
	else
	{
		sort(x.begin(), x.end());
			sort(y.begin(), y.end());
			a = x[0];
			b = 0;
			for (long long i = 0; i < x.size(); i++)
			{
				if (a == x[i])
					b++;
				else
				{
					while (x[i - 1] > y[j])
					{
						if (j == y.size() - 1)
							break;
						j++;
					}
					t = 0;
					while (x[i - 1] == y[j])
					{
						t++;
						if (j == y.size() - 1)
							break;
						j++;
					}
					if (t <= b)
						odwolania = odwolania + t;
					else
						odwolania = odwolania + b;
					a = x[i];
					b = 1;
				}
			}
		while (x[x.size() - 1] > y[j])
		{
			if (j == y.size() - 1)
				break;
			j++;
		}
		t = 0;
		while (x[x.size() - 1] == y[j])
		{
			t++;
			if (j == y.size() - 1)
				break;
			j++;
		}
		if (t <= b)
			odwolania = odwolania + t;
		else
			odwolania = odwolania + b;
	}
	cout << odwolania;
	return 0;
}