Блог пользователя decoder__

Автор decoder__, история, 6 месяцев назад, По-английски

Can anyone help solve this problem?

Not able to attach images here. So sharing a drive link: https://drive.google.com/drive/folders/1C4tsmx-INupvvcPYCNwFcd1OzgvgAK9s

  • Проголосовать: нравится
  • +4
  • Проголосовать: не нравится

»
6 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Can anyone solve the above problem ?

»
6 месяцев назад, # |
Rev. 2   Проголосовать: нравится +4 Проголосовать: не нравится

Not sure if it would work but I am fairly certain.

Spoiler
  • »
    »
    6 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    can you explain the logic behind the solution ?

    • »
      »
      »
      6 месяцев назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      First let's assume all the intervals cover only one point, so $$$b_i = a_i+1$$$ for all intervals. We will generalize this to intervals later.

      Since they are points let's not use the arrays $$$a$$$ and $$$b$$$ and instead we will use an array $$$d$$$. A point $$$i$$$ covers $$$d_i$$$.

      Three are three properties the optimal move has:

      1. We want to move exactly k points, not less.
      2. Moving the points 2, 5, 8 would not be optimal since moving 2 doesn't affect empty interval around 5 since 3 splits them. So we would want to move points with numbers [x, x+k).
      3. If we are moving the points [x, x+k) we want to move all of them so they touch point either $$$x-1$$$ or $$$x+k$$$.

      Now we can solve the problem by trying each x. Imagine we remove all points in the interval [x, x+k), now there is an empty space of size $$$d_{x+k} - d_{x-1} - 1$$$. Let's add the points back in such that they don't split the interval (they don't violate the 3rd property), now the space is of size $$$d_{x+k} - d_{x-1} - 1 - k$$$ because we shortened the interval by k.

      Back to the original problem. The 3 properties of the optimal move is still the same. The only thing that changed is the interval get's shortened by the total of the interval lengths and not $$$k$$$. To get the sum of the lengths of the k intervals in [x, x+k) we can use prefix sums.

»
6 месяцев назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

Anybody else can help, probably the solution given I'm not able to understand