Advertisement
mfgnik

Untitled

Jul 12th, 2020
843
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. amount_of_numbers, amount_of_types = map(int, input().split())
  2. numbers = list(map(lambda x: x - 1, map(int, input().split())))
  3. last_positions = [-1] * amount_of_types
  4. current_types = 0
  5. start_interval, end_interval = 0, 0
  6. start_best, end_best = 0, amount_of_numbers
  7. while True:
  8.     while end_interval < amount_of_numbers:
  9.         if last_positions[numbers[end_interval]] == -1:
  10.             current_types += 1
  11.         last_positions[numbers[end_interval]] = end_interval
  12.         if current_types == amount_of_types:
  13.             break
  14.         end_interval += 1
  15.     if current_types < amount_of_types:
  16.         break
  17.     while last_positions[numbers[start_interval]] != start_interval:
  18.         start_interval += 1
  19.     if end_best - start_best > end_interval - start_interval:
  20.         start_best, end_best = start_interval, end_interval
  21.     last_positions[numbers[start_interval]] = -1
  22.     current_types -= 1
  23.     start_interval += 1
  24.     end_interval += 1
  25. print(start_best + 1, end_best + 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement