fork download
  1. #!/usr/bin/python3
  2.  
  3. def is_no_in_range(n, k) -> bool:
  4. return n >= 1 and n <= k
  5.  
  6. def _main() -> None:
  7. MAX_LEN = int(1e7)
  8. n, m, k = list(map(int, input().split()))
  9. seq = list(map(int, input().split()))
  10.  
  11. assert n == len(seq)
  12.  
  13. for i in range(len(seq)):
  14. seq[i] = (seq[i] % m) + 1
  15. mark = [0 for i in range(105)]
  16. ptr, cnt = 0, 0
  17. ln, a, b = MAX_LEN, -1, -1
  18.  
  19. for i in range(len(seq)):
  20. if is_no_in_range(seq[i], k):
  21. if mark[seq[i]] == 0:
  22. cnt += 1
  23. mark[seq[i]] += 1
  24. while cnt == k and ptr < i:
  25. flag = False
  26. if not is_no_in_range(seq[ptr], k):
  27. flag = True
  28. elif mark[seq[ptr]] > 1:
  29. flag = True
  30. mark[seq[ptr]] -= 1
  31. if not flag:
  32. break
  33. ptr += 1
  34. if cnt == k:
  35. cur_len = ptr - i + 1
  36. if cur_len < ln:
  37. ln = cur_len
  38. a = ptr + 1
  39. b = i + 1
  40. elif cur_len == ln and ptr + 1 < a:
  41. a = ptr + 1
  42. b = i + 1
  43. if ln == MAX_LEN:
  44. print("Rango no encontrado")
  45. else:
  46. print(a, b)
  47.  
  48. if __name__ == '__main__':
  49. _main()
Success #stdin #stdout 0.04s 9796KB
stdin
10 8 4
1 2 3 4 5 6 7 8 9 10
stdout
1 8