가장 적게 비교하는 경우의 횟수를 구하라.
(20)
public class Main{
public static int n;
public static PriorityQueue<Integer> q = new PriorityQueue<>();
public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static StringTokenizer st;
public static void setting() throws IOException {
n = Integer.parseInt(br.readLine());
for(int i = 0;i<n;i++){
q.add(Integer.parseInt(br.readLine()));
}
}
public static int solve(){
int sum = 0;
if(q.size()==1) return 0;
int one = 0,sec=0;
while(q.size()>1){
one = q.poll();
sec = q.poll();
q.add(one+sec);
sum += (one+sec);
}
return sum;
}
public static void main(String[] args) throws IOException{
setting();
System.out.println(solve());
}
}