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

using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, i, pom1, pom2, pom3, l_zmian = 0;
    vector<int>POSORT1(2000000);
    vector<int>POSORT2(2000000);
    cin >> n;
    for (i = 0; i < n; i++)
    {
        cin >> pom1 >> pom2 >> pom3;
        switch (pom1)
        {
        case 1:
            POSORT1[pom2 - pom3 + 999999]++;
            break;
        case 2:
            POSORT2[pom2 - pom3 + 999999]++;
            break;
        }
    }
    for (int i = 0; i < 2000000; i++)
    {
        if ( (POSORT1[i] != 0) && (POSORT2[i] != 0) )
            l_zmian += min(POSORT1[i], POSORT2[i]);
    }

    cout << l_zmian;

    return 0;
}