-
Notifications
You must be signed in to change notification settings - Fork 0
/
Shy Geek.cpp
38 lines (37 loc) · 880 Bytes
/
Shy Geek.cpp
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
class Solution{
public:
Shop shop;
Solution(Shop s){
this->shop = s;
}
int binarySearch(long coins, int& e){
int maxprice = -1;
int s = 0;
int mid = s + (e-s)/2;
while(s <= e){
int price = shop.get(mid);
if(price <= coins){
if(maxprice < price){
maxprice = price;
}
s = mid + 1;
}
else{
e = mid - 1;
}
mid = s + (e-s)/2;
}
return maxprice;
}
long long find(int n, long k){
int first = shop.get(0);
long long count = 0;
int end = n-1;
while(k >= first){
int price = binarySearch(k, end);
count+=((int)(k/price));
k%=price;
}
return count;
}
};