fork(3) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int MAXA = 1000000;
  5.  
  6. int D[1 + MAXA], K[1 + MAXA + 1], P[1 + MAXA];
  7.  
  8. int main()
  9. {
  10. int k, n;
  11. cin >> n >> k;
  12. for (int i = 1; i <= n; ++i) {
  13. int a;
  14. cin >> a;
  15. D[a] = max(D[a], i - P[a]);
  16. P[a] = i;
  17. }
  18. for (int i = 1; i <= MAXA; ++i) {
  19. D[i] = max(D[i], n + 1 - P[i]);
  20. K[D[i]] = i;
  21. }
  22. cout << K[k] << endl;
  23. return 0;
  24. }
Success #stdin #stdout 0s 26952KB
stdin
9 3
2019 7 19 1 7 19 7 7 19
stdout
19