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


using namespace std;

bool compare(pair<int, long long> a, pair<int, long long> b)
{
    if(b.second > a.second)
        return true;
    return false;
}

int main()
{
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;

    vector<pair<int, long long>> cars;

    for(int i = 0; i < n; i++)
    {
        int r;
        long long w, t;
        cin >> r >> w >> t;
        cars.emplace_back(r, w - t);
    }

    sort(cars.begin(), cars.end(), compare);

//    for(int i = 0; i < n; i++)
//        cout<<"r: "<<cars[i].first << " crash nr: "<<cars[i].second<<endl;

    long long last_number = 10000000;
    int how_many_x = 0;
    int how_many_y = 0;
    int result = 0;

    for(int i = 0; i < n; i++)
    {
        if(last_number != cars[i].second)
        {
            last_number = cars[i].second;
            result += min(how_many_x, how_many_y);
            how_many_x = 0;
            how_many_y = 0;
        }
        if(cars[i].first == 1)
            how_many_x++;
        else
            how_many_y++;
    }
    result += min(how_many_x, how_many_y);
    cout<<result<<endl;

    return 0;
}