Why is the answer to this problem always ( N + K — 3) / (K — 1).
Can anyone please help me. editorial is not clear.
| # | User | Rating |
|---|---|---|
| 1 | Benq | 3792 |
| 2 | tourist | 3755 |
| 3 | ecnerwala | 3696 |
| 4 | VivaciousAubergine | 3647 |
| 5 | ksun48 | 3629 |
| 6 | jiangly | 3616 |
| 7 | turmax | 3559 |
| 8 | strapple | 3486 |
| 9 | Kevin114514 | 3427 |
| 10 | Um_nik | 3376 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 162 |
| 2 | adamant | 148 |
| 3 | Um_nik | 146 |
| 4 | Dominater069 | 143 |
| 5 | errorgorn | 141 |
| 6 | cry | 138 |
| 7 | Proof_by_QED | 136 |
| 8 | YuukiS | 135 |
| 9 | chromate00 | 134 |
| 10 | soullless | 133 |
Why is the answer to this problem always ( N + K — 3) / (K — 1).
Can anyone please help me. editorial is not clear.
| Name |
|---|



In each operation, you will select K numbers. Among them one number must be 1, so the remaining K-1 elements will be replaced by 1. That's why after each operation, you will replace K-1 more numbers by 1.
Among N numbers there is already a 1, so you need to replace remaining N-1 numbers by 1.
So, total required operations = (N-1)/(K-1) But if (N-1) is not divisible by (K-1) you need one more operation.
So, answer is ceil((N-1)/(K-1)). Now calculating ceil of a division X/Y is equivalent to (X+Y-1)/Y
That's why you can write ceil((N-1)/(K-1)) = (N-1 + K-2)/(K-1) = (N+K-3)/(K-1)
Could you please explain how in every step you turn k-1 more numbers into 1. My doubt is that if you reach the start or the end of the array you may not be able to change k-1 as you would actually be considering elements which have already turned 1
Upd: i understood