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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX 555555

int cmp(const void *av, const void *bv) {
    int *a = (int *)av;
    int *b = (int *)bv;
    return *a - *b;
}

int H[MAX], V[MAX];

int n, h, v;

int main()
{
    scanf("%d", &n);
    h = v = 0;
    for (int i=0; i<n; i++) {
        int r, w, t;
        scanf("%d %d %d", &r, &w, &t);
        if (r == 1) {
            V[v++] = w-t;
        } else {
            H[h++] = w-t;
        }
    }
    qsort(H, h, sizeof(int), cmp);
    qsort(V, v, sizeof(int), cmp);
    int usun=0;
    int a=0, b=0;
    while (a<h && b<v) {
        if (H[a] < V[b]) {
            a++;
        } else if (H[a] > V[b]) {
            b++;
        } else {
            usun++;
            a++;
            b++;
        }
    }
    printf("%d\n", usun);
    return 0;
}