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

enum delivery_types {
    ONE = 1,
    TWO = 2,
};

int main() {
    int32_t n;
    std::cin >> n;

    constexpr int32_t min_val = 1 - 1'000'000;
    constexpr int32_t max_val = 1'000'000 - 0;
    constexpr int32_t space = max_val - min_val + 1;

    std::vector<std::pair<int32_t, int32_t>> counts(space);
    for (int32_t i = 0; i < n; ++i) {
        delivery_types type;
        int32_t w, t;
        std::cin >> (int &)type >> w >> t;
        auto &two = counts[w - t - min_val];
        (type == ONE ? two.first : two.second) += 1;
    }

    int32_t discarded = 0;
    for (auto two: counts) {
        discarded += std::min(two.first, two.second);
    }
    std::cout << discarded << "\n";
}