티스토리 뷰
학기 중에는 해설 로직을 포함하지 않습니다.
문제
https://www.acmicpc.net/problem/11399
언어
자바 Java
코드
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
Integer[] persons = new Integer[n];
String[] input = br.readLine().split(" ");
for (int i = 0; i < input.length; i++)
persons[i] = Integer.parseInt(input[i]);
Arrays.sort(persons, Integer::compare);
List<Integer> result = new ArrayList<>();
result.add(0);
for(int i = 0; i < n; i++) {
int withDrawTime = getWithDrawTime(persons, result.get(result.size() - 1), i);
result.add(withDrawTime);
}
long sum = result.stream().mapToInt(Integer::intValue).sum();
System.out.println(sum);
}
private static int getWithDrawTime(Integer[] persons, int prevTime, int order) {
return prevTime + persons[order];
}
}