CMing's blog

By CMing, 2 years ago, In English

Problem D

The three parts from top to bottom on the left are: non overlapping, partially overlapping, and containing — the three situations. And $$$\Delta$$$ means the contribution will be made to the answer if we exchange $$$b_i$$$ and $$$b_j$$$

Perhaps the text in the picture is a bit blurry: Only situations within the first box will have a positive contribution to the answer. To maximize the contribution, we must find the longest distance beteween two segements. Let's assume that all segements are in the form of $$$a$$$ less than $$$b$$$, if $$$b$$$ less than $$$a$$$, then swap $$$b$$$ and $$$a$$$. Note that this will not affect the answer because the distance won't be changed. So we just need to find the largest $$$a$$$ and the smallest $$$b$$$

Code

The time complexity is $$$O(n)$$$.

If there are any errors, please make corrections

Full text and comments »

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