Блог пользователя daihan

Автор daihan, 9 лет назад, По-английски

I am trying to find out the logic to solve this problem , KOIREP — Representatives , i tried for 7 days still get no idea to solve it .

Can anyone please tell me how can i effeciently solve it ? Problem tagged with Sliding window alias two pointer .

  • Проголосовать: нравится
  • +2
  • Проголосовать: не нравится

»
9 лет назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

This could be solved using two pointers. Firstly sort all numbers and for each of them remember the group ID to which it belong to. Then for each position l in sorted array we can find the smallest possible r such as there are n different groups on the segment from l to r. Time Complexity : O(n * m * log(n * m));