[Programmers] 입국 심사

Date:

[Programmers] 입국 심사

Problem URL : 입국 심사

#include <vector>
#include <algorithm>

using namespace std;

long long solution(int n, vector<int> times) {
    long long answer = 0;
    int maxTime = 0;
    int timeSize = times.size();
    for(int i = 0; i < timeSize; i++) {
        if(maxTime < times[i]) {
            maxTime = times[i];
        }
    }

    long long start = 1;
    long long end = (long long) maxTime * n;
    long long mid;

    while(start <= end) {
        mid = (start + end) / 2;
        long long cnt = 0;

        for(int i = 0; i < times.size(); i++) {
            cnt += mid / times[i];
        }

        if(cnt < n) {
            start = mid + 1;
        }else {
            answer = mid;
            end = mid - 1;
        }
    }

    return answer;
}

댓글