Editorial for DMOPC '15 Contest 3 P1 - Quality Scenes
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Consider sorting the video clips and, subsequently, their endpoints, , , , and :
If , swap and and and ; otherwise, do not swap anything.
Now, we can check if the endpoint of the leftmost video clip (starts at and ends at ) overlaps with the rightmost video clips (starts at and ends at ):
If the start of the rightmost video clip () is less than the end of the leftmost video clip (), they must overlap, so output YES
; otherwise, output NO
.
Time Complexity:
Bonus: How would you solve this problem if there were video clips?
Comments