#P12304. [ICPC 2022/2023 WF] Bridging the Gap

[ICPC 2022/2023 WF] Bridging the Gap

题目描述

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 22 walkers at a time and there are 44 walkers with crossing times 11 minute, 22 minutes, 55 minutes and 1010 minutes, respectively. The shortest time of 1717 minutes can be achieved by the following sequence of crossings. First, the two fastest walkers cross in 22 minutes. Second, the fastest walker crosses back in 11 minute. Third, the two slowest walkers cross in 1010 minutes. Fourth, the second-fastest walker crosses back in 22 minutes. Fifth, the two fastest walkers cross in 22 minutes.

输入格式

The first line of input contains two integers nn and cc, where nn (2n1042 \le n \le 10^4) is the number of walkers, and cc (2c1042 \le c \le 10^4) is the number of walkers the bridge can hold at a time.

Then follows a line containing nn integers t1,,tnt_1, \ldots , t_n (1ti1091 \le t_i \le 10^9 for all ii). The ithi^\text{th} walker takes time tit_i to cross.

输出格式

Output the minimum total time it takes for the entire group to cross the bridge.

4 2
1 2 10 5

17

4 6
1 2 10 5

10