CodingTest/99클럽2024스터디
99클럽 코테 스터디 13일차 TIL, 프로그래머스 / 입국심사
mrawesome
2024. 8. 3. 15:53
https://school.programmers.co.kr/learn/courses/30/lessons/43238?language=cpp
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
int maxTime = 1000000000;
long long solution(int n, vector<int> times) {
long long answer = 0;
sort(times.begin(), times.end());
long long minT = 1, maxT = (long long)times[times.size() - 1] * n;
while(minT < maxT)
{
long long midT = (minT + maxT) / 2;
long long totN = 0;
for (long long time : times)
{
totN += midT / time;
}
if (totN >= n)
{
maxT = midT - 1;
answer = midT;
}
else
{
minT = midT + 1;
}
}
return answer;
}