Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 좋은 수열
- 위클리 6주차
- ElementTree
- 백트랙킹
- Java
- 몯느 순열
- 1174
- 프로그래머스
- dfs
- 백준
- BFS
- 순열장난
- 백트렉킹
- 너비우선탐색
- 39080
- openssl
- 10597
- 문서자동화
- 부분 수열의 합
- 재귀
- DP
- 복서 정렬하기
- 입실 퇴실
- 백트래킹
- 그래프
- 완전 탐색
- 코딩테스트
- BOJ
- 위클리 챌린지
- 줄어드는 숫자
Archives
개발자-H 입니다.
BOJ - ATM 본문
https://www.acmicpc.net/problem/11399
11399번: ATM
첫째 줄에 사람의 수 N(1 ≤ N ≤ 1,000)이 주어진다. 둘째 줄에는 각 사람이 돈을 인출하는데 걸리는 시간 Pi가 주어진다. (1 ≤ Pi ≤ 1,000)
www.acmicpc.net
- 그리디 알고리즘이다.
- 정렬 후 누적 값을 출력하면된다.
- 정렬에 PriorityQueue를 사용하였다.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
public static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws Exception {
PriorityQueue<Integer> queue = new PriorityQueue<>();
int numOfPeople = Integer.parseInt(br.readLine());
String[] s = br.readLine().split(" ");
for(String time : s) {
queue.offer(Integer.parseInt(time));
}
int sum = 0;
int last = 0;
while(!queue.isEmpty()) {
Integer poll = queue.poll();
sum += last + poll;
last += poll;
}
System.out.println(sum);
}
}
'Algorithm > 문제 풀이' 카테고리의 다른 글
프로그래머스 - 카카오프렌즈 컬러링북 (0) | 2021.08.17 |
---|---|
BOJ - 동전 0 (0) | 2021.08.16 |
BOJ - 1, 2, 3 더하기 (0) | 2021.08.16 |
BOJ - 토마토 (7576) (0) | 2021.08.14 |
BOJ - 최소비용 구하기 (0) | 2021.08.13 |
Comments