#include <string>
#include <vector>
#include <algorithm>
using namespace std;
long long cal(long long mid,vector<int> v) {
long long num = 0;
for (int i = 0; i < v.size(); i++) {
num += (mid / v[i]);
}
return num;
}
long long solution(int n, vector<int> times) {
sort(times.begin(), times.end());
long long maxvalue = times[times.size() - 1];
long long answer = maxvalue * n;
long long low = 0;
long long high = answer;
while (low <= high) {
long long mid = (low + high) / 2;
long long value = cal(mid, times);
if (value >= n) {
answer = min(answer, mid);
high = mid - 1;
}
else
low = mid + 1;
}
return answer;
}
프로그래머스