그리디 알고리즘 문제이다.
내 순서가 되기 까지 걸린 시간 + 내가 걸리는 시간
을 계속 더해주며 제일 오래 걸리는 사람까지 더해주면 정답이 나온다.public class bj11399 {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
int[] time = new int[N];
String[] split = br.readLine().split(" ");
for (int i = 0; i < N; i++) {
time[i] = Integer.parseInt(split[i]);
}
Arrays.sort(time);
int answer = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j <= i; j++) {
answer += time[j];
}
}
System.out.println(answer);
br.close();
}
}