Skip to content

Instantly share code, notes, and snippets.

@veigavitor
Created May 18, 2023 20:09
Show Gist options
  • Save veigavitor/4ea66a9ec46a2cabac7c2094f14bc494 to your computer and use it in GitHub Desktop.
Save veigavitor/4ea66a9ec46a2cabac7c2094f14bc494 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
// lemos a entrada
int n, d;
cin >> n >> d;
vector<int> t(n);
for(int i = 0; i < n; i++) {
cin >> t[i];
}
// passamos pelos tempos, começando no segundo, checando
// se o tempo atual menos o último tempo é menor que 'd'
// se for, retornamos o tempo atual e finalizamos o programa
for(int i = 1; i < n; i++) {
if(t[i] - t[i-1] <= d) {
cout << t[i] << endl;
return 0;
}
}
// se não houver duplo clique, retornamos -1
cout << -1 << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment