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
#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
    std::ios_base::sync_with_stdio(false);
    int n;
    std::cin>>n;
    std::vector<std::pair<int,int>> data;
    for(int i=0;i<n;++i)
    {
        int type, coordinate, time;
        std::cin>>type>>coordinate>>time;
        data.push_back({coordinate-time,type});
    }

    std::sort(data.begin(),data.end());
    int c = 1000000;
    int x = 0, y = 0;
    int count = 0;
    for(auto d:data)
    {
        if(c != d.first) { count+=std::min(x, y); c = d.first; x = 0; y = 0;}
        d.second == 1 ? ++x : ++y;
    }
    count+=std::min(x, y);
    std::cout<<count<<std::endl;
    return 0;
}