CF 1065 C
题目
[1600]
There is a toy building consisting of n towers. Each tower consists of several cubes standing on each other. The i-th tower consists of hi cubes, so it has height hi.
Let’s define operation slice on some height H as following: for each tower i, if its height is greater than H, then remove some top cubes to make tower’s height equal to H. Cost of one “slice” equals to the total number of removed cubes from all towers.
Let’s name slice as good one if its cost is lower or equal to k (k≥n).

Calculate the minimum number of good slices you have to do to make all towers have the same height. Of course, it is always possible to make it so.
Input
The first line contains two integers n and k (1≤n≤2⋅105, n≤k≤109) — the number of towers and the restriction on slices, respectively.
The second line contains n space separated integers h1,h2,…,hn (1≤hi≤2⋅105) — the initial heights of towers.
Output
Print one integer — the minimum number of good slices you have to do to make all towers have the same heigth.
思路
整体策略
我们的目标是用最少的“切片”次数把所有塔变平。一个很自然的想法是:让每一次切片都尽可能地多切一些,直到成本快要超出限制 k 为止。
代码
1 |
|