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
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>
#include <vector>
using namespace std;

int N, a, b, c;

int main() { // grudzień jest, trzy projekty do końca wekendu, kolos w poniedziałęk, :(
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N;
    vector<pair<int, int>> poziome, pionowe;

    for (int i = 0; i < N; i++) {
        cin >> a >> b >> c;
        if (a == 1) {
            poziome.push_back({b, c});
        } else {
            pionowe.push_back({b, c});
        }
    }

    if (poziome.empty() || pionowe.empty()) {
        cout << "0\n";
        return 0;
    }

    int removed = 0;
    bool cos_sie_tnie = true;
    int maxP, id, curr;
    while (cos_sie_tnie) {
        maxP = 0; a = 1; id = 0;
        for (int i = 0; i < poziome.size(); i++) {
            curr = 0;
            for (int j = 0; j < pionowe.size(); j++) {
                if (poziome[i].first + pionowe[j].second == poziome[i].second + pionowe[j].first)
                    curr++;
            }
            if (curr > maxP) {
                maxP = curr;
                id = i;
            }
        }

        for (int i = 0; i < pionowe.size(); i++) {
            curr = 0;
            for (int j = 0; j < poziome.size(); j++) {
                if (pionowe[i].first + poziome[j].second == pionowe[i].second + poziome[j].first)
                    curr++;
            }
            if (curr > maxP) {
                maxP = curr;
                id = i;
                a = 2;
            }
        }

        if (maxP == 0) {
            cos_sie_tnie = false;
        } else {
            removed++;
            if (a == 1) {
                poziome[id] = {removed, 0};
            } else {
                pionowe[id] = {removed, 0};
            }
        }
    }

    cout << removed << "\n";

}