Bridging the Gap
시간 제한4초메모리 제한1024 MB
다리 정원 c와 각자의 이동 시간이 주어질 때, 모든 사람이 건너는 데 필요한 최소 총 시간을 구한다.
문제
A group of walkers arrives at a river in the night. They want to cross a bridge, which can hold a limited number of walkers at a time. The walkers have just one torch, which needs to be used when crossing the bridge. Each walker takes a certain time to cross; a group crossing together must walk at the slowest walker’s pace. What is the shortest time it takes for all walkers to cross the bridge?
For example, Sample Input 1 assumes the bridge can hold walkers at a time and there are walkers with crossing times minute, minutes, minutes and minutes, respectively. The shortest time of minutes can be achieved by the following sequence of crossings. First, the two fastest walkers cross in minutes. Second, the fastest walker crosses back in minute. Third, the two slowest walkers cross in minutes. Fourth, the second-fastest walker crosses back in minutes. Fifth, the two fastest walkers cross in minutes.
입력
The first line of input contains two integers and , where () is the number of walkers, and () is the number of walkers the bridge can hold at a time.
Then follows a line containing integers ( for all ). The th walker takes time to cross.
출력
Output the minimum total time it takes for the entire group to cross the bridge.