백준: 11399(ATM)

강지안·2023년 7월 18일
0

baekjoon

목록 보기
115/186

문제

코드

import java.util.Arrays;
import java.util.Scanner;

public class q11399 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] person = new int[N];
        for(int i=0; i<N; i++) person[i] = sc.nextInt();
        Arrays.sort(person);

        int[] memo = new int[N];
        int totalTime = 0;
        for(int i=0; i<N; i++) {
            if(i==0) memo[0] = person[i];
            else memo[i] = memo[i-1] + person[i];
            totalTime += memo[i];
        }
        System.out.println(totalTime);
    }
}

2개의 댓글

comment-user-thumbnail
2023년 7월 18일

가치 있는 정보 공유해주셔서 감사합니다.

답글 달기
comment-user-thumbnail
2023년 7월 18일

아주 유익한 내용이네요!

답글 달기