공부기록/백준

[백준] 11399번 ATM

메델 2024. 2. 4. 15:05
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	
	public static void main(String[] args) {
		
		Scanner kb = new Scanner(System.in);
		int N = kb.nextInt();
		
		int[] persons = new int[N];
		
		for(int i=0; i<N; i++) {
			persons[i] = kb.nextInt();
		}
		
		Arrays.sort(persons);
		
		int[] times = new int[N];
		
		times[0] = persons[0];
		int sum = persons[0];
		
		for(int i=1; i<N; i++) {
			times[i] = times[i-1]+ persons[i];
			sum+=times[i];
		}

		System.out.println(sum);

	}


}