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
#include <bits/stdc++.h>
using namespace std;
int n;

struct D {
    int x;
    int r;
    D(int _r, int _x) {
        r = _r;
        x = _x;
    }
};

bool cmp(D a, D b) 
{
    if(a.x!=b.x) return a.x < b.x;
    return a.r < b.r;
}
vector<D>sam;

int main() {
    cin>>n;
    int r, w, t;

    for(int i = 0; i < n; i++) {
        cin>>r>>w>>t;
        sam.push_back(D(r,w-t));
    }
    sort(sam.begin(),sam.end(),cmp);

    int wyn = 0;
    int last = -1;
    int ile = 0;
    for(int i = 0; i < sam.size();i++) {
        if(sam[i].r==1){
            if(last == sam[i].x) {
                ile++;
            }else{
                last = sam[i].x;
                ile = 1;
            }
        } else {
            if(last == sam[i].x) {
                if(ile > 0) {
                    ile--;
                    wyn++;
                }
            }
        }
    }
    cout<<wyn<<"\n";
    return 0;
}