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
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector <pair<int,int> > a;
    vector <pair<int,int> > a2;
    vector <pair<int,int> > b;
    vector <pair<int,int> > b2;
    for (int i=0; i<n;i++){
        int r, w, t;
        cin >> r >> w >> t;
        if (r==1){
            a.push_back(make_pair(w,t));
        }else{
            b.push_back(make_pair(w,t));
        }
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    int wynik=0;
    for (int i=0; i<a.size();i++){
        if (i+1!=a.size()){
            if (a[i]!=a[i+1]){
                a2.push_back(a[i]);
            }
        }else{
            a2.push_back(a[i]);
        }
    }
    wynik+=(int)a.size()-(int)a2.size();
    for (int i=0; i<b.size();i++){
        if (i+1!=b.size()){
            if (b[i]!=b[i+1]){
                b2.push_back(b[i]);
            }
        }else{
            b2.push_back(b[i]);
        }
    }
    wynik+=(int)b.size()-(int)b2.size();
    map<int, pair<int,int> > m;
    for (int i=0; i<b2.size();i++){
        m[b2[i].first-b2[i].second].first++;
    }
    for (int i=0; i<a2.size();i++){
        m[a2[i].first-a2[i].second].second++;
    }

    for (int i=0; i<b2.size();i++){
        wynik+=min(m[b2[i].first-b2[i].second].first,m[b2[i].first-b2[i].second].second);
        m[b2[i].first-b2[i].second].first=0;
    }
    cout << wynik<<endl;
}