728x90
이전글 :: 2021/02/17 - [Programming/알고리즘] - [java, 알고리즘, 그리디] :: 1이 될 때까지
11399번: ATM
첫째 줄에 사람의 수 N(1 ≤ N ≤ 1,000)이 주어진다. 둘째 줄에는 각 사람이 돈을 인출하는데 걸리는 시간 Pi가 주어진다. (1 ≤ Pi ≤ 1,000)
www.acmicpc.net
package com.algorithm.greedyEx04;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class GreedyEx04 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
String [] arr = br.readLine().split(" ");
int [] numArr = new int[n];
for(int i = 0; i < n; i++){
numArr[i] = Integer.parseInt(arr[i]);
}
Arrays.sort(numArr);
int result = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < i + 1; j++){
result += numArr[j];
}
}
System.out.println(result);
}
}
접근방법
인출 소요 시간이 적은 순서로 정렬한다.
728x90
'Programming > 알고리즘' 카테고리의 다른 글
[java, 알고리즘, 그리디] :: 백준 - 잃어버린 괄호 (0) | 2021.02.18 |
---|---|
[java, 알고리즘, 그리디] :: 백준 - 동전 0 (0) | 2021.02.18 |
[java, 알고리즘, 그리디] :: 1이 될 때까지 (0) | 2021.02.17 |
[java, 알고리즘, 그리디] :: 숫자 카드 게임 (0) | 2021.02.17 |
[java, 알고리즘, 그리디] :: 큰 수의 법칙 (1) | 2021.02.14 |
댓글