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
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
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
Name |
---|
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 ?