[백준] 11399번 : ATM - JAVA [자바]

가오리·2024년 1월 26일
0
post-thumbnail

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


그리디 알고리즘 문제이다.

  1. 각 사람들이 인출하는데 걸리는 시간을 저장한 배열을 오름차순으로 정렬한다.
  2. 제일 적게 걸리는 사람부터 내 순서가 되기 까지 걸린 시간 + 내가 걸리는 시간 을 계속 더해주며 제일 오래 걸리는 사람까지 더해주면 정답이 나온다.

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();
    }
}
profile
가오리의 개발 이야기

0개의 댓글

관련 채용 정보