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
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;

    vector<int>SetA, SetB;
    for(int i=0;i<n;i++){
        int m,p,t;
        cin >> m >> p >> t;
        if(m==1)
            SetA.push_back(p-t);
        else
            SetB.push_back(p-t);
    }

    sort(SetA.begin(), SetA.end());
    sort(SetB.begin(), SetB.end());

    int result=0;
    for(int a=0,b=0;a<(int)SetA.size() && b<(int)SetB.size();)
        if(SetA[a]==SetB[b]){
            result++;
            a++;
            b++;
        }
        else if(SetA[a]<SetB[b])
            a++;
        else
            b++;

    cout << result << "\n";    
    return 0;
}