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
#include <bits/stdc++.h>
using namespace std;
map<int, int> roznice_a;
map<int, int> roznice_u;
int r[1000010], w[1000010], t[1000010];
int kolizje;
vector<pair<int, int>> aleje;
vector<pair<int, int>> ulice;
vector<pair<int, int>> dostawy;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> r[i] >> w[i] >> t[i];
        if (r[i] == 1)
        {
            aleje.push_back(make_pair(w[i], t[i]));
        }
        else
        {
            ulice.push_back(make_pair(w[i], t[i]));
        }
    }
    for (auto i : aleje)
    {
        auto itr = roznice_a.emplace(i.first - i.second, 0).first;
        ++itr->second;
    }
    for (auto i : ulice)
    {
        auto itr = roznice_u.emplace(i.first - i.second, 0).first;
        ++itr->second;
    }
    int wynik = 0;
    for (auto it = roznice_a.begin(); it != roznice_a.end(); ++it)
    {
        auto i = roznice_u.find(it->first);
        if (i == roznice_u.end())
            continue;
        else
        {
            wynik += min(it->second, i->second);
        }
    }
    cout << wynik;
}