diff options
author | Santo Cariotti <santo@dcariotti.me> | 2021-02-06 19:56:36 +0100 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2021-02-06 19:56:36 +0100 |
commit | d2edbc38cac8da52f58c5cd3da6c0c625fa05736 (patch) | |
tree | a51e9a4e56fc9d4c7c9e37576dceedca3a0c72b4 /Year_1/Programming_2/coding_contest/ladri.cpp | |
parent | 98f34040820dc3a964b7be59a698323e8cc6c8a3 (diff) |
conf: rename
Diffstat (limited to 'Year_1/Programming_2/coding_contest/ladri.cpp')
-rw-r--r-- | Year_1/Programming_2/coding_contest/ladri.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/Year_1/Programming_2/coding_contest/ladri.cpp b/Year_1/Programming_2/coding_contest/ladri.cpp new file mode 100644 index 0000000..04e8e65 --- /dev/null +++ b/Year_1/Programming_2/coding_contest/ladri.cpp @@ -0,0 +1,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; +} |