728x90
https://school.programmers.co.kr/learn/courses/30/lessons/43238
(1) C++
#include <string>
#include <vector>
#include <algorithm>
#include <string.h>
using namespace std;
long long solution(int n, vector<int> times) {
long long answer = 0;
sort(times.begin(), times.end());
long long start = 1;
long long end = n * (long long)times.back();
while(start <= end){
long long mid = (start + end) / 2;
long long person = 0;
for(int i = 0; i < times.size(); i++){
person += (mid / (long long)times[i]);
}
if (person >= n){
end = mid - 1;
answer = mid;
}
else{
start = mid + 1;
}
}
return answer;
}
(2) Python
def solution(n, times):
times.sort()
start = 1
end = max(times) * n
while (start <= end):
mid = (start + end) // 2
people = 0
for time in times:
people += (mid // time)
if people < n:
start = mid + 1
else:
answer = mid
end = mid - 1
return answer
728x90
'Study > Coding Test' 카테고리의 다른 글
[프로그래머스] C++ 문자열 다루기 관련 문제들 (0) | 2023.08.02 |
---|---|
[프로그래머스] 배달 Python, C++ (0) | 2023.08.02 |
[프로그래머스] 베스트앨범 Python, C++ (0) | 2023.08.01 |
[프로그래머스] 의상 Python, C++ (0) | 2023.08.01 |
[프로그래머스] K번째수 Python, C++ (0) | 2023.08.01 |