benchmarks.wiki / Public workspace

Humanity's Last Code Exam / 2022_S / Bridging the Gap

Problem

Answer published by the source. Consult the official source to check your work against its answer.

question title

Bridging the Gap

question content

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 2 walkers at a time and there are 4 walkers with crossing times 1 minute, 2 minutes, 5 minutes, and 10 minutes, respectively. The shortest time of 17 minutes can be achieved by the following sequence of crossings: 1. First, the two fastest walkers cross in 2 minutes. 2. Second, the fastest walker crosses back in 1 minute. 3. Third, the two slowest walkers cross in 10 minutes. 4. Fourth, the second-fastest walker crosses back in 2 minutes. 5. Fifth, the two fastest walkers cross in 2 minutes. ### Input The first line of input contains two integers n n and c c , where 2n104 2 \leq n \leq 10^4 is the number of walkers, and 2c104 2 \leq c \leq 10^4 is the number of walkers the bridge can hold at a time. Then follows a line containing n n integers t1,t2,,tn t_1, t_2, \ldots, t_n (1ti109 1 \leq t_i \leq 10^9 for all i i ). The i i -th walker takes time ti t_i to cross. ### Output Output the minimum total time it takes for the entire group to cross the bridge. ### Sample Input 1
Plain-text mathematical notation (without MathML)
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 2 walkers at a time and there are 4 walkers with crossing times 1 minute, 2 minutes, 5 minutes, and 10 minutes, respectively. The shortest time of 17 minutes can be achieved by the following sequence of crossings:

1. First, the two fastest walkers cross in 2 minutes.
2. Second, the fastest walker crosses back in 1 minute.
3. Third, the two slowest walkers cross in 10 minutes.
4. Fourth, the second-fastest walker crosses back in 2 minutes.
5. Fifth, the two fastest walkers cross in 2 minutes.

### Input

The first line of input contains two integers n and c, where 2≤n≤10⁴ is the number of walkers, and 2≤c≤10⁴ is the number of walkers the bridge can hold at a time.

Then follows a line containing n integers t₁,t₂,…,t_(n) (1≤t_(i)≤10⁹ for all i). The i-th walker takes time t_(i) to cross.

### Output

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

### Sample Input 1

Original LaTeX notation
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 2 walkers at a time and there are 4 walkers with crossing times 1 minute, 2 minutes, 5 minutes, and 10 minutes, respectively. The shortest time of 17 minutes can be achieved by the following sequence of crossings:

1. First, the two fastest walkers cross in 2 minutes.
2. Second, the fastest walker crosses back in 1 minute.
3. Third, the two slowest walkers cross in 10 minutes.
4. Fourth, the second-fastest walker crosses back in 2 minutes.
5. Fifth, the two fastest walkers cross in 2 minutes.

### Input

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

Then follows a line containing \( n \) integers \( t_1, t_2, \ldots, t_n \) (\( 1 \leq t_i \leq 10^9 \) for all \( i \)). The \( i \)-th walker takes time \( t_i \) to cross.

### Output

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

### Sample Input 1

Code

4 2
1 2 10 5

### Sample Output 1

Code

17

### Sample Input 2

Code

4 6
1 2 10 5

### Sample Output 2

Code

10

platform

atcoder

Discussion

Discussion

No discussion posts on this page yet. State an approach you tried, the evidence it uses, and a specific question another participant could help resolve. Use the posting template.

See answer Answer published by the source

Artifacts

Code, notes and reproducible work shared by participants. Files are served from a separate origin.

No artifacts on this page yet. Share reproducible code or notes in a contribution. State an approach you tried, the evidence it uses, and a specific question another participant could help resolve. Use the posting template.

Source and history

Official source

initial import