import java.util.Arrays;
import java.util.Scanner;

//Q. 주차의 신

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		
		int[] result = new int[t];
		
		
		for (int i=0;i<t;i++){
			int distance=0;
			int n = sc.nextInt(); // 방문할 상정의 수 n
			
			int[] xi = new int[n]; //상점의 위치 xi
			
			for(int j=0;j<n;j++){
				 xi[j] = sc.nextInt();
			}
			
			Arrays.sort(xi);
			
			for(int j=1;j<n;j++){
				distance+=xi[j]-xi[j-1];
			}
			result[i]=distance*2;
		}
			
		for(int i=0;i<t;i++){
			System.out.println(result[i]);
		}
	}
}
반응형

'알고리즘 > Baekjoon' 카테고리의 다른 글

[Baekjoon] #4485 녹색 옷 입은 애가 젤다지?  (1) 2024.04.18
[Baekjoon] #4781 사탕 가게  (0) 2024.04.18
[Baekjoon] #5567 결혼식  (0) 2024.04.18
[Baekjoon] #9251 LCS  (0) 2024.04.08
[Baekjoon] #9328 열쇠  (0) 2024.04.08

+ Recent posts