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
#include<bits/stdc++.h>
using namespace std;
int n,x[1000005],y[1000005],z[1000005];
map<int,pair<int,int> > t;
int main()
{
    cin >> n;
    for (int i = 1 ; i <= n ; i++)
    {
        cin >> x[i] >> y[i] >> z[i];
        if(x[i] == 1)
            t[y[i]-z[i]].first++;
        else
            t[y[i]-z[i]].second++;
    }
    int W = 0;
    for (int i = 1 ; i <= n ; i++)
    {
        if(t[y[i]-z[i]].first!= 0 && t[y[i]-z[i]].second != 0)
        {
            W+=min(t[y[i]-z[i]].first,t[y[i]-z[i]].second);
            t[y[i]-z[i]].first = 0;
        }
    }
    cout << W;
}