https://www.acmicpc.net/problem/11399
Java Code
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
PriorityQueue<Integer> pq = new PriorityQueue<Integer>((o1,o2)->o1-o2);
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
for (int i = 0; i < N; i++) {
int time = Integer.parseInt(st.nextToken());
pq.add(time);
}
int total = 0;
int ans = 0;
while(!pq.isEmpty()) {
int val = pq.poll();
total += val;
ans += total;
}
System.out.println(ans);
}
}
'Algorithm' 카테고리의 다른 글
[백준] JAVA - 20056. 마법사 상어와 파이어볼 (0) | 2021.03.30 |
---|---|
[백준] JAVA - 2629. 양팔저울 (0) | 2021.03.29 |
[백준] JAVA - 1261. 알고스팟 (0) | 2021.03.27 |
[백준] JAVA - 16953. A > B (0) | 2021.03.27 |
[백준] JAVA - 14502. 연구소 (0) | 2021.03.26 |