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
57
58
#include <iostream>
#include <sstream>
#include <algorithm>
#include <unordered_map>
using namespace std;

main (int arc, char ** argv) {

    int n,suma = 0;
    cin >> n;
    //cout << n << '\n';

    std::unordered_map<int, int> ulice;
    std::unordered_map<int, int> aleje;
    std::unordered_map<int,int>::iterator it;
    for (int i = 0; i < n; i++)
    {
        int r,w,t = 0;
        cin >> r >> w >> t;
        //cout << r << " " << w << " " << t << '\n';

        if (r == 1) {
            it = ulice.find(w-t);
            if (it == ulice.end() ) {
                ulice.insert(make_pair(w-t, 1));
            } else {
                it->second++;
            }
        } else {
            it = aleje.find(w-t);
            if (it == ulice.end() ) {
                aleje.insert(make_pair(w-t, 1));
            } else {
                it->second++;
            }
        }
    }

    if (ulice.size() > aleje.size()) {
        it = aleje.begin();
        for (; it != aleje.end(); ++it) {
            if (ulice.find(it->first) != ulice.end()) {
                suma += min(it->second, ulice.at(it->first));
            }
        }
    } else {
        it = ulice.begin();
        for (; it != ulice.end(); ++it) {
            if (aleje.find(it->first) != aleje.end()) {
                suma += min(it->second, aleje.at(it->first));
            }
        }
    }


    cout << suma <<'\n';
    return 0;
}