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
#include <bits/stdc++.h>

using namespace std;

vector <int> s1;
vector <int> s2;

int main(){
    int n;
    cin>>n;
    s1.push_back(INT_MAX);
    s2.push_back(INT_MAX);
    while (n--){
        int k, i, t;
        scanf("%d", &k);
        scanf("%d", &i);
        scanf("%d", &t);
        if (k==1){
            s1.push_back(i-t);
        }else{
            s2.push_back(i-t);
        }
    }
    sort(s1.begin(), s1.end());
    sort(s2.begin(), s2.end());
    int n1 = 0;
    int n2 = 0;
    int wynik = 0;
    while (!(s1[n1]==INT_MAX&&s2[n2]==INT_MAX)){
        //cout<<n1<<' '<<n2<<endl;
        if (s1[n1]==s2[n2]){
            ++wynik;
            ++n1;
            ++n2;
        }else{
            if (s1[n1]>s2[n2]){
                ++n2;
            }else{
                ++n1;
            }
        }
    }
    cout<<wynik;
}