1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
| #include <string>
#include <vector>
#include <algorithm>
using namespace std;
//이 문제를 어떻게 이분 탐색으로 푸냐 ?
//-> 최대시간을 기준으로 이분 탐색을 통해 그 시간에 몇명을 처리할 수 있는지를 따라가는 풀이방법!
bool cmp(long long a,long long b)
{
return a > b;
}
long long solution(int n, vector<int> times) {
long long answer = 0;
sort(times.begin(),times.end(),cmp);
long long maxTime = n*(long long)times[0];
long long left = 1;
long long right = maxTime;
while(left<=right)
{
long long mid = (left+right) / 2;
long long cnt = 0;
for (int i=0;i<times.size();i++)
{
cnt += (mid/(long long)times[i]);
}
if (cnt < n)
{
left = mid+1;
}
else
{
right = mid-1;
answer = mid;
}
}
return answer;
}
|