fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void executeTime() {
  5. cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " secs";
  6. }
  7.  
  8. int main() {
  9.  
  10. int n, k; cin >> n >> k;
  11.  
  12. vector<int> v(n);
  13. for (auto &x : v) {
  14. cin >> x;
  15. }
  16.  
  17. unordered_map<int, int> mp;
  18. int f = 1;
  19.  
  20. for (int i = 0; i < n; i++) {
  21. if (mp.count(v[i])) {
  22. if (i - mp[v[i]] <= k) {
  23. f = 0;
  24. cout << "YES" << endl;
  25. break;
  26. }
  27. }
  28.  
  29. mp[v[i]] = i;
  30. }
  31.  
  32. if (f) cout << "NO" << endl;
  33.  
  34. executeTime();
  35. return 0;
  36. }
Success #stdin #stdout #stderr 0.01s 5320KB
stdin
10 5
1 23 1 7 50
1 32 23 1 50
stdout
YES
stderr
Time Taken: 0.005518 secs