Updated:

1. 문제 링크

https://www.acmicpc.net/problem/11399

2. 사용 알고리즘

그리디

3. 풀이

인출하는데 걸리는 시간 기준으로 오름차순 정렬 후 합 계산

4. 소스 코드

4-1. C++

https://github.com/dev-aiden/problem-solving/blob/main/boj/11399.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <algorithm>

using namespace std;

int arr[1003];

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n; cin >> n;
    for(int i = 0; i < n; ++i) cin >> arr[i];
    sort(arr, arr + n);
    int ans = arr[0], temp = arr[0];
    for(int i = 1; i < n; ++i) {
        temp += arr[i];
        ans += temp;
    }
    cout << ans << "\n";
    return 0;
}

4-2. JAVA

https://github.com/dev-aiden/problem-solving/blob/main/boj/11399.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    static int arr[] = new int[1003];

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        StringTokenizer st = new StringTokenizer(br.readLine());
        for(int i = 0; i < n; ++i) arr[i] = Integer.parseInt(st.nextToken());
        Arrays.sort(arr, 0, n);
        int ans = arr[0], temp = arr[0];
        for(int i = 1; i < n; ++i) {
            temp += arr[i];
            ans += temp;
        }
        System.out.println(ans);
    }
}

Updated:

Leave a comment