小杰的签到题
import java.util.Scanner;
import java.util.Arrays;
//三张桌子,随机排队和签到,求最早最后一个队伍完成的签到时间
import java.util.Arrays;
//三张桌子,随机排队和签到,求最早最后一个队伍完成的签到时间
//算法分析,每当一个队伍到达时,判断是否需要排队,不需要则找到最早签到完成并空出的桌子进行签到,需要则就在最早可能完成签到的桌子前排队
public class Main{
public static void main(String [] args){
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for(int c =0;c<T&&sc.hasNext();c++){
public static void main(String [] args){
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for(int c =0;c<T&&sc.hasNext();c++){
int n = sc.nextInt();
int []array= new int[n];
for(int i = 0;i<n;i++){
array[i] = sc.nextInt();
}
int b = sc.nextInt();
int []desk = new int[]{0,0,0};
Arrays.sort(array);
if(n<=2){
System.out.println(array[n-1]+b);
continue;
}else{
for(int i=0;i<3;i++){
desk[i] = array[i] +b;
}
int []array= new int[n];
for(int i = 0;i<n;i++){
array[i] = sc.nextInt();
}
int b = sc.nextInt();
int []desk = new int[]{0,0,0};
Arrays.sort(array);
if(n<=2){
System.out.println(array[n-1]+b);
continue;
}else{
for(int i=0;i<3;i++){
desk[i] = array[i] +b;
}
for(int i=3;i<n;i++){
Arrays.sort(desk);
if(array[i]>=desk[0]){
desk[0] = array[i]+b;
}else{
desk[0] = desk[0] + b;
}
}
Arrays.sort(desk);
System.out.println(desk[2]);
}
}
}
}
Arrays.sort(desk);
if(array[i]>=desk[0]){
desk[0] = array[i]+b;
}else{
desk[0] = desk[0] + b;
}
}
Arrays.sort(desk);
System.out.println(desk[2]);
}
}
}
}