본문 바로가기
Java

[백준] 센티와 마법의 뿅망치 성공

by 간장공장공차장 2024. 11. 17.
반응형

예외 케이스

1 50 1
10

거인이 사실은 난쟁이였다는 사실을 고려할 필요하 있다..

import java.util.*;
import java.io.*;


public class Main {
    public static void TallKiller() throws IOException {

        String answer = "YES";
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String info = br.readLine();

        String[] parse_info = info.split(" ");

        int tall_num = Integer.parseInt(parse_info[0]);
        int centi_tall = Integer.parseInt(parse_info[1]);
        int limit_hit = Integer.parseInt(parse_info[2]);

        PriorityQueue<Integer> tall_guys = new PriorityQueue<>((o1, o2) -> o2 - o1);

        for (int i = 0; i < tall_num; i++) {
            tall_guys.offer(Integer.parseInt(br.readLine()));
        }

        int hit_count = 0;

        while (limit_hit > 0) {

            int biggest_tall = tall_guys.poll();

            if(biggest_tall < centi_tall){
                break;
            }

            if (biggest_tall > 1) {
                tall_guys.offer(biggest_tall / 2);
            } else {
                tall_guys.offer(1);
            }

            limit_hit--;
            hit_count++;

            if(limit_hit == 0) {
                if (tall_guys.peek() < centi_tall) {
                    answer = "YES";
                } else {
                    answer = "NO";
                }
                break;
            }

        }


        if (answer.equals("YES")) {
            System.out.println("YES");
            System.out.println(hit_count + "");}
        else {
            System.out.println("NO");
            System.out.println(tall_guys.peek() + "");
        }
    }

    public static void main(String[] args) throws IOException {

        TallKiller();

    }
}
반응형