본문 바로가기

Algorithm/백준

프로그래머스 입국심사 - 자바

package refactor;

public class Pro_입국심사 {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int n = 6;
        int times[] = {7,10};
        System.out.println(solution.solution(n,times));
    }

    static class Solution {
        public long solution(int n, int[] times) {
            long answer = 0;
            long sum = 0;
            long start = 0;
            long end = (long)n * 1000000000;
            for (int time : times) {
                sum += time;
            }

            while(start <= end){
                long half = (start+end) / 2;
                long temp = 0;
                for (int time : times) {
                    if(time != 0) temp += half / time;
                }
                if(temp < n){
                    start = half + 1;
                }else{
                    end = half - 1;
                }
            }
            return start;
        }
    }
}

'Algorithm > 백준' 카테고리의 다른 글

백준 17245 서버실 - 자바  (0) 2024.08.22
백준 1365 꼬인 전깃줄 - 자바  (0) 2024.08.22
백준 6236 용돈관리 - 자바  (0) 2024.08.22
백준 2805 나무 자르기 - 자바  (0) 2024.08.22
백준 2776 암기왕 - 자바  (0) 2024.08.22