-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2300.cpp
More file actions
27 lines (26 loc) · 771 Bytes
/
2300.cpp
File metadata and controls
27 lines (26 loc) · 771 Bytes
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
class Solution {
public:
vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {
vector<int>ans(spells.size());
sort(potions.begin(),potions.end());
for(int i=0;i<spells.size();i++){
ans[i]=com(spells[i],potions,success);
}
return ans;
}
int com(int spells,vector<int>& potions,long long &success){
int l=0,h=potions.size()-1,mid;
int temp=potions.size();
while(l<=h){
mid=l+(h-l)/2;
long long p=potions[mid]*(long long)spells;
if(p>=success){
h=mid-1;
temp=mid;
}else{
l=mid+1;
}
}
return (potions.size()-temp);
}
};