1. 程式人生 > >Codeforces551C:GukiZ hates Boxes(二分+貪心)

Codeforces551C:GukiZ hates Boxes(二分+貪心)

Note

First sample: Student will first move to the first pile (1 second), then remove box from first pile (1 second), then move to the second pile (1 second) and finally remove the box from second pile (1 second).

Second sample: One of optimal solutions is to send one student to remove a box from the first pile and a box from the third pile, and send another student to remove a box from the third pile. Overall, 5

 seconds.

Third sample: With a lot of available students, send three of them to remove boxes from the first pile, four of them to remove boxes from the second pile, five of them to remove boxes from the third pile, and four of them to remove boxes from the fourth pile. Process will be over in 5 seconds, when removing the boxes from the last pile is finished.

題意:
有n個地點,每個地點有a[i]個箱子,然後有m個人,每個人從第i個位置移動到第i+1的位置花費1S,每個人移動一個箱子花費1S,要求把所有箱子全部移除花費的最小時間是多少


思路:
先二分列舉答案,然後對每個答案判斷是否能夠滿足即可