【编程题解】Drive car

这是一道编程题,题目要求解决n个人去餐厅的问题,只有一辆车且每次最多载三人。每个人的独自驾驶时间不同,当两人或三人同行时,驾驶时间取他们中最长的。为了安全至少需要两人同行。目标是最短时间将所有人送到餐厅。输入包括测试样例数、人数及每个人的独自驾驶时间,输出是最短驾驶时间。已给出个人用JAVA编写的不一定正确的解答,欢迎交流。
摘要由CSDN通过智能技术生成

Description

n individuals want to travel, the place to stay is far from the restaurant, you need to drive by, but there is only one car in the hotel

The car can sit for a maximum of three people at a time, and each person drives to the restaurant alone for a[i];

When two or three people take a car together, the time spent is the longest driving time among all of them;

For safety, at least two people are required to drive at a time.

So what is the shortest time it takes to get everyone to the restaurant.

Input

The first line is an integer T, indicating the number of test samples.

The first line of each test sample is a positive integer n, indicating the number of people participating in the tour.

The second line is n positive integers a[i], representing the time when n people drive to restaurant alone;

Data range:2≤n<100000,0<a[i]<100000

Output

For each test sample, a minimum driving time is output.

Each result is on a line.

Sample Input 1 

2
2
1 2
4
1 1 1 1

Sample Output 1

2
3

Personal Answer  (using language:JAVA)  Not necessarily right

public class Main {
    public static void main(String[] args) {
        System.out.println("Unsolved");
    }
}

Welcome to communicate!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值