fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. bool identical(vector<int>v,int k){
  5. map<int,int>m;
  6. for(int i=0;i<v.size();i++){
  7. for(int j=i+1;j<v.size();j++){
  8. if(v[i]==v[j] && j-i<=k)return true;
  9. }
  10. }
  11. return false;
  12. }
  13.  
  14. int main() {
  15. // your code goes here
  16. int n;cin>>n;
  17. vector<int>v(n);
  18. for(int i=0;i<n;i++)cin>>v[i];
  19. int k;cin>>k;
  20. if(identical(v,k)){
  21. cout<<"YES"<<endl;
  22. }else{
  23. cout<<"NO"<<endl;
  24. }
  25. return 0;
  26. }
Success #stdin #stdout 0s 5320KB
stdin
5
3 1 2 3 4
2
stdout
NO