https://www.acmicpc.net/problem/19638
우선순위 큐를 사용해서 풀었다.
최소값이 1이거나 키보다 작은 값일 경우 반복문을 탈출 후 결과 출력한다
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int H = Integer.parseInt(st.nextToken());
int T = Integer.parseInt(st.nextToken());
PriorityQueue<Integer> pq = new PriorityQueue<>(((o1, o2) -> o2 - o1));
for(int i = 0; i < N; i++){
pq.add(Integer.parseInt(br.readLine()));
}
int count = 0;
for(int i = 0; i < T; i++){
if(pq.peek() < H || pq.peek() == 1){
break;
}
else if(pq.peek() >= H){
int num = pq.poll();
count++;
num /= 2;
pq.add(num);
}
}
if(pq.peek() >= H){
System.out.println("NO");
System.out.println(pq.peek());
} else{
System.out.println("YES");
System.out.println(count);
}
}
}
'PS > 백준' 카테고리의 다른 글
[백준] 우주 탐사선 - Java 17182 (0) | 2024.10.21 |
---|---|
[백준] 램프 - Java 1034 (0) | 2024.10.10 |
[백준] 풍선 터트리기 - Java 32377 (0) | 2024.10.02 |
[백준] 두수의 합 - Java 9024 (0) | 2024.10.02 |
[백준] 진우의 민트초코우유 - Java 20208 (0) | 2024.09.29 |