10148 - Advertisement
Moderator: Board moderators
-
- New poster
- Posts: 48
- Joined: Sat Apr 06, 2013 6:02 pm
Re: 10148 - Advertisement
What is the algorithm for solving this kind of problem? Can this be solved using Binary Indexed Tree?
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10148 - Advertisement
You can solve it using a greedy strategy.
Sort the intervals by non-decreasing end.
For each interval, if the length is <= K then put a billboard at every location.
Otherwise place billboards at the largest unused location within that interval until at least K billboards have been placed inside it.
Sort the intervals by non-decreasing end.
For each interval, if the length is <= K then put a billboard at every location.
Otherwise place billboards at the largest unused location within that interval until at least K billboards have been placed inside it.
Check input and AC output for thousands of problems on uDebug!