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
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 155 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | nor | 152 |
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
Название |
---|
Can anyone solve the above problem ?
Not sure if it would work but I am fairly certain.
Sort the array.
Make the array 1-indexed.
Set $$$a_0 = b_0 = 0$$$, $$$a_{n+1} = b_{n+1} = n+1$$$.
Create an array $$$c$$$ such that $$$c_i = b_i - a_i$$$
Create an array $$$p$$$ such that $$$p_0 = c_0 = 0$$$ and $$$p_i = p_{i-1} + c_i$$$. (prefix sum of the array c)
Set $$$ans = 0$$$.
For every $$$0 \leq i \leq n-k$$$ do:
can you explain the logic behind the solution ?
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:
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.
Thanks. Any reference codeforces problem, I can use to relate with this approach?
I don't know of a problem like this but you may solve problems with greedy and sortings tags if you want something similar. O7
Anybody else can help, probably the solution given I'm not able to understand
Anyone can help ?