fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int k;cin>>k;
  6. int n; cin>>n;
  7. int f=0;
  8. unordered_map<int,int> mp;
  9. for(int i=0;i<n;i++){
  10. int t; cin>>t;
  11. if(mp.count(t) && i-mp[t]<=k) f=1;
  12. mp[t]=i;
  13.  
  14. }
  15. cout<<f;
  16. }
Success #stdin #stdout 0s 5320KB
stdin
2
10
1 2 3 4 5 6 7 8 9 8
stdout
1