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
#include <iostream>
#include <vector>
#include <bits/stdc++.h> 

using namespace std;

int main() {

    int n;
    short typ;
    int garaz, wyjazd;
    vector<int> vec1;
    vector<int> vec2;

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> typ >> garaz >> wyjazd;
        if (typ == 1)
            vec1.push_back(garaz-wyjazd);
        else
            vec2.push_back(garaz-wyjazd);
    }

    sort(vec1.begin(), vec1.end()); 
    sort(vec2.begin(), vec2.end()); 

    int curr, end;
    if (vec1.size() == 0 || vec2.size() == 0) {
        cout << 0;
        return 0;
    }
    curr = vec1[0];
    end = vec1[vec1.size()-1];

    //cout << "\npoczatkowe curr = " << curr << endl;
    int odp = 0, i = 0, j = 0, k = 0;
    //for (int k = 0; k < vec1.size() + vec2.size(); k++) 
    while (i < vec1.size() && j < vec2.size()) {
        if (vec2[j] == vec1[i]) {
            odp++;
            //curr = vec1[i+1];
            //cout << "+\n";
            i++;
            j++;
            //cout << "zwiekszam indeks dla vec1 i vec2\n";
            //continue;
        }
        if (vec2[j] < curr) {
            j++;
            //cout << "zwiekszam indeks dla vec2\n";
        }
        if (vec1[i] < curr) {
            i++;
            //cout << "zwiekszam indeks dla vec1\n";
        }
        if (vec1[i] > curr) {
            curr = vec1[i];
            //cout << vec1[i] << " (vec1)wieksze od curr" << endl;
        }
        if (vec2[j] > curr) {
            curr = vec2[j];
            //cout << vec2[j] << " (vec2)wieksze od curr" << endl;
        }
        //cout << "curr= " << curr << endl;
    }
    cout << odp;
    return 0;
}