• Home
  • About
    • Ryureka Moment photo

      Ryureka

      Sin Prisa, Sin Pausa

    • About Me
    • Facebook
    • Github
    • Youtube
  • Projects
  • Posts
    • Posts
    • ProblemSolvings
    • Tags
    • Blog
    • Examples
  • ProblemSolving
    • ProblemSolving
    • BOJ
    • Programmers
    • SWEA
    • LeetCode
  • FrontEnd
    • FrontEnd
    • HTML
  • BackEnd
    • BackEnd
    • Server
      • Server
      • Spring
      • NodeJS
    • DataBase
      • DataBase
      • MySQL
      • MongoDB
  • Programming
    • Programming
    • Java
    • JS
    • Python
    • CleanCode
  • ComputerScience
    • DataStructure
    • Algorithm

[BOJ] 3079. 입국심사

15 Apr 2026

Reading time ~1 minute

  • 풀이

풀이

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int M = sc.nextInt();
		
		int[] times = new int [N];
		for(int i = 0; i < N; i++) {
			times[i] = sc.nextInt();			
		}
		
		long answer = 0l;
		long left = 1l;
		long right = 1_000_000_000_000_000_000l;
		
		while(left <= right) {
			long mid = left + right >>> 1;
			if(isOK(mid,times,M)) {
				answer = mid;
				right = mid - 1;
			} else {
				left = mid + 1;
			}
		}		
		System.out.println(answer);
	}
	
	public static boolean isOK(long mid, int[] times, int M) {
		long sum = 0;
		for(int i = 0; i < times.length; i++) {
			sum += mid/times[i];
			if(sum >= M) return true;
		}
		return false;
	}
}


이분탐색매개변수탐색 Share