-->
当前位置:首页 > 题库 > 正文内容

PROGRAMMING:cross the river

Luz3年前 (2021-05-10)题库372
There are n people who want to cross a river, but they only have a boat that can carry two people at most. So we have to figure out a way to dispatch the boats back and forth so that everyone can cross the river. Everyone has their own speed, and two people in the same boat depend on the speed of the slow one. Your task is to come up with the fastest strategy for everyone to cross the river.
###Input format:
The first line of input is a positive integer t (1 < = T < = 20), which indicates the number of test case groups. Here's the group t use case. The first line of each use case is a positive integer n, and the second line is n positive integers indicating the rowing speed of each person. Each use case will not exceed 1000 people, and each person's rowing time will not exceed 100 seconds.
###Output format:
For each use case, output the shortest time (seconds) that all n people can cross the river.
###Input example:
```in
two
three
1 3 7
four
1 2 5 10
```
###Output example:
```out
eleven
seventeen
```







answer:If there is no answer, please comment

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。