OJ

[BOJ] 27724 팝핀 소다 (JAVA)

P3PP4 2023. 4. 19. 10:00

https://www.acmicpc.net/problem/27724

 

27724번: 팝핀 소다

입력의 첫 번째 줄에 대회에 참가하는 선수의 수 $N$, 일어날 수 있는 이변의 수 $M$, 시은이의 탄산 내성 $K$가 공백으로 구분되어 주어진다. 주어지는 모든 수는 정수이다. $(2 \le N \le 262\,144;$ $0 \le

www.acmicpc.net

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st;

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

        st = new StringTokenizer(br.readLine(), " ");
        int N = Integer.parseInt(st.nextToken());
        int M = Integer.parseInt(st.nextToken());
        int K = Integer.parseInt(st.nextToken());

        int n = 0;
        while (1 < N) {
            N /= 2;
            n++;
        }

        int a = 1;
        int cnt = 0;
        while (a < K) {
            a *= 2;
            cnt++;
        }
        if (a != K) cnt--;

        int result = cnt + M;

        System.out.print(n < result ? n : result);

    }

}