fischerman's blog

By fischerman, history, 3 years ago, In English

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.

  • Vote: I like it
  • +14
  • Vote: I do not like it

»
3 years ago, # |
  Vote: I like it +6 Vote: I do not like it

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 years ago, # |
  Vote: I like it +15 Vote: I do not like it

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.