ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1303. Minimal Coverage

If you want a solution
Posted by Mahilewets 1 Jun 2017 11:37
The problem is quite evil.  The problem is actually very easy.  It is hard to understand that the problem is that easy.
Possible solution.
First ,  eliminate all such segments I=[l;r],  that l>M or r<0, because of such I's can't appear in the answer.
Second,  build your dp[].
Your dp[x]  contains rightmost right end of all such segments [l;r],  that l<=x.
Finally,  just start from segment whose right end is dp[0],  jump to a  segment whose right end is dp[dp[0]] and so on.

How to build dp[x]?
I have used an additional array right_end[y].  Where right_end[y] is the right end of a segment with maximal length from all segments whose left end is y.
dp[x] =max(dp[x-1], right_end[x]).