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

int main(){
    std::unordered_map<int, size_t> horizontal;
    std::unordered_map<int, size_t> vertical;

    int n;
    std::cin >> n;

    for(int x=0; x<n; x++){
        int type, place, time;
        std::cin >> type >> place >> time;

        int diff = place - time;
        if(type == 1){
            horizontal[diff]++;
        } else {
            vertical[diff]++;
        }
    }

    auto i = horizontal.begin();
    auto j = vertical.begin();

    int sum = 0;

    while(i != horizontal.end() && j != vertical.end()){
        
        if(i->first == j->first){
            sum += std::min(i->second, j->second);
            i++;
            j++;
        } else if(i->first > j->first){
            j++;
        } else {
            i++;
        }
    }
    std::cout << sum << std::endl;
}