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 | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | maomao90 | 163 |
2 | Um_nik | 163 |
4 | atcoder_official | 161 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | nor | 153 |
9 | Dominater069 | 153 |
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 ?