Simple C++ Binary Search :)
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n- the approach that is used here is binary search.\n- So first we sort th
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n- the approach that is used here is `binary search`.\n- So first we `sort` the potions.\n- then we traverse through `every element in spell` and multiply it to the potions.\n- and because our potions is `sorted` we can apply binary search now.\n- so by doing that we can get the minimum element in `potions` which has multiplication `>=` to our success.\n- when we get that element then every element from its right or is bigger than that element is gonna pass.\n- so we push the `total size of potions - index of minimum success element`.\n- after doing it for all the elements in `spells`, we return the answer\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: `O(nlog(n+m))` #correct me if i\'m wrong cause not sure perfectly :)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n`Upvote ! It just takes 1 click :)`\n\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n        vector<int> ans;\n        int n= spells.size();\n        int m = potions.size();\n        sort(potions.begin(), potions.end());\n        for (int i=0;i<n;i++){\n            int spell = spells[i];\n            int start = 0;\n            int end = m-1;\n            while(start<=end){\n                int mid = start + (end-start)/2;\n                long long product = (long) spell * potions[mid];\n                if(product>=success){\n                    end = mid-1;\n                } \n                else{\n                    start = mid+1;\n                }\n            }\n            ans.push_back(m-start);\n            \n        }\n        return ans;\n        \n    }\n};\n```\n![Upvote.jpeg](https://assets.leetcode.com/users/images/1b85f3f9-1fb4-466e-8a35-8dd5e22e1a9f_1680437696.0481274.jpeg)
['Binary Search', 'C++']