summaryrefslogtreecommitdiff
path: root/Year_1/Programming_2/coding_contest/ladri.cpp
blob: 04e8e65f943257f435884fd2f2f3898e5b6763a6 (plain)
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
#include<iostream>
#include<fstream>
#include<vector>

using namespace std;

int main() {
    ifstream in("input.txt");
    ofstream out("output.txt");

    for(short _ = 0; _ < 100; ++_) {
        int N, K, M;
        in >> N >> K >> M;
        int* path = new int[N+1];
        int i;
        for(i = 0; i < N; ++i)
            in >> path[i];

        path[i] = M;
        int start = 0;
        vector<int> values;
        /* 1 31 33 38 62 69 93 97 98 99 */
        /* x x     x  x   x          x       
         * K = 30
         */
        for(int i = 0; i < N+1; ++i) {
            if(path[i] - start > K) {
                for(int j = i-1; j >= 0; --j) {
                    if(path[i] - path[j] <= K) {
                        values.push_back(path[j]);
                        start = path[j];
                        i = j;
                        break;
                    }
                }
            }
        }

        // Stampa la path corretta per debug
        for(auto const& i: values) 
            cout << i << ' ';

        cout << endl;
        out << values.size() << endl;
        delete[] path;
    }


    out.close();
    in.close();

    return 0;
}