File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ //https://www.acmicpc.net/problem/14241
2+ import java .io .BufferedReader ;
3+ import java .io .IOException ;
4+ import java .io .InputStreamReader ;
5+ import java .util .Collections ;
6+ import java .util .PriorityQueue ;
7+ import java .util .StringTokenizer ;
8+
9+ public class BOJ_S3_14241_슬라임합치기 {
10+ public static void main (String [] args ) throws IOException {
11+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
12+ int N = Integer .parseInt (br .readLine ());
13+
14+ PriorityQueue <Integer > pq = new PriorityQueue <>(Collections .reverseOrder ());
15+
16+ StringTokenizer st = new StringTokenizer (br .readLine ());
17+ for (int i = 0 ; i < N ; i ++) {
18+ pq .add (Integer .parseInt (st .nextToken ()));
19+ }
20+
21+ int ans = 0 ;
22+
23+ while (pq .size () >= 2 ) {
24+ int x = pq .poll ();
25+ int y = pq .poll ();
26+
27+ ans += x * y ;
28+ pq .add (x +y );
29+ }
30+
31+ System .out .println (ans );
32+
33+ }
34+ }
You can’t perform that action at this time.
0 commit comments