[BOJ] 그리디 알고리즘/11399번 - ATM

aio·2021년 2월 18일
0

백준 알고리즘

목록 보기
7/9

문제

제출답안

...
	import java.util.*;
	
	public class Main {
		public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);
			int humanCount = sc.nextInt();
			int[] withdrawalTime = new int[humanCount];
			
			for(int i=0; i<withdrawalTime.length; i++) {
				withdrawalTime[i] = sc.nextInt();
			}
			
			Arrays.sort(withdrawalTime);	//	인출시간이 적은 순서대로 정렬
			
			int sumWithdrawalTime = 0;
			for(int j=0; j<withdrawalTime.length; j++) {
				if(j != 0) {	// 첫 사람이 아니라면 인출차례가 오기까지 기다린 시간을 모두 더함
					for(int k=j; k>=0; k--) {
						sumWithdrawalTime += withdrawalTime[k];
					}
				}else {		// 첫 사람이라면 기다린 시간이 없으므로 본인이 인출한 시간만 더함
					sumWithdrawalTime += withdrawalTime[j];
				}
			}
			
			System.out.println(sumWithdrawalTime);
			
			sc.close();
		}
		
	}

...

출처

백준 알고리즘

0개의 댓글