summaryrefslogtreecommitdiff
path: root/I_anno/Programmazione_2/coding_contest/stazioni.cpp
blob: 29ede4486266eb9fa01f5d522b17c1e253d15758 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include<iostream>
#include<fstream>
#include<algorithm>
#include<vector>

using namespace std;

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

    for(int ts = 0; ts < 1; ++ts) {
        int N, S;
        in >> N >> S;
        vector<long> st;
        vector<vector<long>> paths;
        vector<vector<long>> paths2;
        vector<vector<long>> paths3;

        int e;
        for(int i = 0; i < N; ++i) {
            in >> e;
            st.push_back(e);
        }

        int index{};
        for(int i = 0; i < N-S+1; ++i) {
            for(int j = 0; j < N; ++j) {
                paths.push_back(vector<long>{});
                paths[index].push_back(i);
                for(int k = j; paths[index].size() < S; ++k) {
                    int t = (k == N) ? 0 : k;
                    if(k > N) break;
                    paths[index].push_back(t);
                }
                sort(begin(paths[index]), end(paths[index]));
                if(paths[index].size() == S)
                    paths2.push_back(paths[index]);
                ++index;
            }
        }
        for(int i = 0; i < paths2.size(); ++i) {
            bool check{true};
            if(paths2[i].size() != S) continue;
            for(int j = 0; j < paths2[i].size()-1; ++j) {
                if(paths2[i].at(j) == paths2[i].at(j+1)) {
                    check = false;
                    break;
                }
            }
            if(check)
                paths3.push_back(paths2[i]);
        }

        for(auto const& i : paths3) {
            for(auto const& j : i) 
                cout << st[j] << ' ';

            cout << endl;
        }
        cout << endl;

        int major{};
        for(int i = 0; i < paths3.size(); ++i) {
            vector<long> diffs;
            for(int j = 0; j < paths3[i].size()-1; ++j) {
                int p1 = st[paths3[i][j+1]];
                int p2 = st[paths3[i][j]];
                diffs.push_back(p1 - p2);
            }
            int miner = *min_element(begin(diffs), end(diffs));
            if(miner > major)
                major = miner;
        }
        cout << ts << ' ' << major << endl;
        out << major << endl;
    }

    in.close();
    out.close();
    return 0;
}