1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <bits/stdc++.h>
#include <iostream>

using namespace std;
int tab[2000002][2];
int n, min_v, max_v;
int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int ty, loc, ti; 
        cin >> ty >> loc >> ti;
        tab[1000000+loc-ti][ty-1]++;
        min_v = min(loc-ti, min_v);
        max_v = max(loc-ti, max_v);
    }

    int counter = 0;
    for (int i = 1000000 + min_v; i <= 1000000 + max_v; i++) {
        counter += min(tab[i][0], tab[i][1]);
    }
    cout << counter << endl;
    return 0;
}