lina_os

Untitled

Apr 9th, 2025
8
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  8. int n, k;
  9. cin >> n >> k;
  10. vector<int>v(n);
  11. for (int i=0; i<n; i++) {
  12. cin >> v[i];
  13. }
  14. int x=v[k-1];
  15. for (int i=k; i<n; i++) {
  16. if (v[i]!=x) {
  17. cout << -1;
  18. return 0;
  19. }
  20. }
  21. for (int i=n-1; i>-1; i--) {
  22. if (v[i]!=x) {
  23. cout << i+1;
  24. return 0;
  25. }
  26. }
  27. return 0;
  28.  
  29. }
  30.  
  31.  
  32.  
Advertisement
Add Comment
Please, Sign In to add comment