#C2407. Minimum Total Container Height
Minimum Total Container Height
Minimum Total Container Height
You are given n oranges and a container parameter r. Each container has a fixed capacity defined by a base height of \(2r\). The oranges have various diameters. Your task is to determine the minimum total container height required to store all oranges according to this rule:
- Sort the list of orange diameters in non-decreasing order.
- For each orange (with diameter \(d\)), try to place it in an existing container. A container can hold an orange if its fixed capacity \(2r\) is at least \(d\). When an orange is placed in a container, the container's total accumulated height increases by \(d\).
- If no container is found (i.e. in all existing containers \(2r < d\)), start a new container with base capacity \(2r\) and add the orange to it.
The answer is the sum of the heights of all containers after packing all the oranges. Note that the decision is made greedily in the sorted order of diameters.
inputFormat
The first line of input contains two integers n and r (number of oranges and the container parameter, respectively).
The second line contains n space-separated integers representing the diameters of the oranges.
outputFormat
Output a single integer: the minimum total height of all containers required to store the oranges.
## sample1 5
8
8