본문 바로가기
알고리즘 & 자료구조/백준

백준 1783

by 신재권 2022. 8. 12.
package baekjoon.그리디;

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

class Main1783 {

   static int N, M;

   public static void main(String[] args) throws Exception {
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      StringTokenizer st = new StringTokenizer(br.readLine());
      N = Integer.parseInt(st.nextToken());
      M = Integer.parseInt(st.nextToken());

      if (N == 1) {
         System.out.println(1);
      } else if (N == 2) {
         System.out.println(Math.min(4, (M + 1) / 2));
      } else {
         int[] ans = {-1, 1, 2, 3, 4, 4, 4, 5, 6};
         if (M <= 8) {
            System.out.println(ans[M]);
         } else {
            System.out.println(M - 2);
         }
      }

   }
}

'알고리즘 & 자료구조 > 백준' 카테고리의 다른 글

백준 2847  (0) 2022.08.15
백준 1700  (0) 2022.08.13
백준 2720  (0) 2022.08.11
백준 2437  (0) 2022.08.10
백준 1080  (0) 2022.08.08