728x90

=>정답률도 높고 그렇게 어려운 문제도 아닌거 같다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package beak_joon;
 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
 
public class BeakJoon_11399 {
 
    public static void main(String[] args) throws IOException {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
        int N = Integer.parseInt(br.readLine());
        
        int [] arr = new int[N];
 
        StringTokenizer st = new StringTokenizer(br.readLine()," ");
 
        for(int i = 0; i< N; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        // 정렬 
        Arrays.sort(arr);
 
        int prev = 0;    // 이전까지의 대기시간 누적합         
        int total = 0;    // 사람별 대기시간 총합 
 
        for(int i = 0; i < N; i++){
            // 이전까지의 대기시간 + 현재 사람이 걸리는 시간.
            total += prev + arr[i];
 
            // 이전까지의 누적합 + 현재 걸리는 시간
            prev += arr[i];
        }
 
        System.out.println(total);
    }
}
//정리하자면 그냥 오름차순으로 정렬하고 더해주면 된다.
 
cs
728x90

'Dev > 알고리즘 ,자료구조' 카테고리의 다른 글

[Algorithm]BeakJoon_2981  (0) 2021.07.20
[Algorithm]BeakJoon_1541  (0) 2021.07.18
[Algorithm]BeakJoon_1931  (0) 2021.07.18
[Algorithm]BeakJoon_14681  (0) 2021.07.18
[Algorithm]BeakJoon_1330  (0) 2021.07.18