fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. int k,n;
  7. cin>>k>>n;
  8. int arr[n];
  9. for(int i=0;i<n;i++){
  10. cin>>arr[i];
  11. }
  12.  
  13. for(int i=0;i<n;i++){
  14. for(int j=i+1;j<n;j++){
  15. if((arr[i]==arr[j]) && (j-i<=k)){
  16. cout<<"yes";
  17. return 0;
  18.  
  19.  
  20. }
  21.  
  22. }
  23. }
  24. cout<<"no";
  25. return 0;
  26. }
Success #stdin #stdout 0s 5248KB
stdin
2 6
1 2 3 2 4 5
stdout
yes