-
[Baekjoon Online Judge] 11399번: ATM문제 풀이/Baekjoon Online Judge 2020. 12. 23. 19:44
11399번: ATM
import java.io.*; import java.util.Arrays; public class Baekjoon11399 { public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(System.out)); int n = Integer.parseInt(bufferedReader.readLine()); int[] withdrawalTimes = new int[n]; // 인출 시간을 넣어둘 int 배열 String[] inputSplit = bufferedReader.readLine().split(" "); for( int i = 0; i < n; ++i ) { withdrawalTimes[i] = Integer.parseInt(inputSplit[i]); } Arrays.sort(withdrawalTimes); // 오름차순으로 베열 정렬 int result = 0; for (int i = 0; i < n; i++) { result += withdrawalTimes[i] * (n - i); // 사용한 횟수만큼 더해줌 } bufferedWriter.write(String.valueOf(result)); bufferedWriter.flush(); bufferedReader.close(); bufferedWriter.close(); } }
'문제 풀이 > Baekjoon Online Judge' 카테고리의 다른 글
[Baekjoon Online Judge] 2217번: 로프 (0) 2020.12.26 [Baekjoon Online Judge] 5585번: 거스름돈 (0) 2020.12.26 [Baekjoon Online Judge] 1931번: 회의실배정 (0) 2020.12.25 [Baekjoon Online Judge] 11047번: 동전 0 (0) 2020.12.25 [Baekjoon Online Judge] 2839번: 설탕 배달 (0) 2020.12.23