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

Автор fischerman, история, 3 года назад, По-английски

Problem link — https://codedrills.io/contests/amrita-icpc-practice-session-7/problems/alibaba-and-thieves There is an editorial, but it just describes the algorithm instead of the idea (or I just don't get it). Can anyone please describe why is this correct? Also, if there are more problems where we need to sort some intervals and do something greedily, please share.

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

»
3 года назад, # |
  Проголосовать: нравится +6 Проголосовать: не нравится

At a given time say you have some intervals that can be taken. Then you want to take the one that ends first because others that end later can be taken later.

»
3 года назад, # |
  Проголосовать: нравится +15 Проголосовать: не нравится

My approach was iterating over time, and whenever it is possible to include one or more coins, greedily choose one which has the least right range, because other with greater right range will still be available in next second. Though, time <= 1e9 but whenever we don't have any coin possible at that particular time, simply move to the nearest upcoming left range.