본문 바로가기
알고리즘 & 자료구조/백준

백준11399

by 신재권 2022. 7. 7.
package baekjoon.그리디;

import java.util.*;
import java.io.*;

class Main11399 {

   public static void main(String[] args) throws Exception {
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      StringTokenizer st;
      int N = Integer.parseInt(br.readLine());
      int[] A = new int[N + 1];
      st = new StringTokenizer(br.readLine());
      PriorityQueue<Integer> pq = new PriorityQueue<>();
      for (int i = 1; i <= N; i++) {
         pq.add(Integer.parseInt(st.nextToken()));
      }
      int tmp = 0;
      int ans = 0;
      while (!pq.isEmpty()) {
         tmp += pq.poll();
         ans += tmp;
      }
      System.out.println(ans);
   }
}

 

'알고리즘 & 자료구조 > 백준' 카테고리의 다른 글

백준 1339  (0) 2022.07.10
백준 13305  (0) 2022.07.08
백준 2156  (0) 2022.07.05
백준 1931  (0) 2022.07.05
백준 1541  (0) 2022.07.04