http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=30216
這題就是把數列排序再累加到n-1並把所有累加的數相加就是答案了
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
while (scn.hasNext()) {
int n = scn.nextInt(), arr[] = new int[n], tot = 0, num = 0;
for (int i = 0; i < n; i++)
arr[i] = scn.nextInt();
Arrays.sort(arr);
for (int i = 0; i < n - 1; i++) {
num += arr[i];
tot += num;
}
System.out.println(tot);
}
}
/*
題目:[C_SO51-易] 排程問題
作者:1010
時間:西元 2016 年 7 月 */
}