[JavaC++/Python] Straignt Forward with Explantion
Explanation\nFor each spell,\nit needs ceil integer of need = success * 1.0 / spell.\n\nBinary search the index of first potion >= need in the sorted potions.\n
# **Explanation**\nFor each `spell`,\nit needs ceil integer of `need = success * 1.0 / spell`.\n\nBinary search the `index` of first `potion >= need` in the sorted `potions`.\nThe number of potions that are successful are `potions.length - index`\n\nAccumulate the result `res` and finally return it.\n<br>\n\n# **Complexity**\nTime `O(mlogm + nlogm)`\nSpace `O(n)`\n<br>\n\n**Java**\n```java\n\tpublic int[] successfulPairs(int[] spells, int[] potions, long success) {\n\t\tArrays.sort(potions);\n\t\tTreeMap<Long, Integer> map = new TreeMap<>();\n        map.put(Long.MAX_VALUE, potions.length);\n\t\tfor (int i = potions.length - 1; i >= 0; i--) {\n\t\t\tmap.put((long) potions[i], i);\n\t\t}\n\t\tfor (int i = 0; i < spells.length; i++) {\n            long need = (success + spells[i] - 1) / spells[i];\n\t\t\tspells[i] = potions.length - map.ceilingEntry(need).getValue();\n\t\t}\n\t\treturn spells;\n\t}\n```\n**C++**\n```cpp\n    vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {\n        sort(potions.begin(), potions.end());\n        vector<int> res;\n        for (int a: spells) {\n            long need = (success + a - 1) / a;\n            auto it = lower_bound(potions.begin(), potions.end(), need);\n            res.push_back(potions.end() - it);\n        }\n        return res;\n    }\n```\n\n**Python**\n```py\n    def successfulPairs(self, spells, potions, success):\n        potions.sort()\n        return [len(potions) - bisect_left(potions, (success + a - 1) // a) for a in spells]\n```\n<br>\n\n# Solution II: Two Sum\nSort `spells`\nSort `potions`\nNow it\'s basic two sum question, though it\'s two mulplication.\n\nTime `O(nlogn + mlogm)`\nSpace `O(n)`\n\n**Java**\n```java\n    public int[] successfulPairs(int[] spells, int[] potions, long success) {\n        int[] spells0 = spells.clone();\n        Arrays.sort(potions);\n        Arrays.sort(spells);\n        HashMap<Integer, Integer> count = new HashMap<>();\n        int n = spells.length, m = potions.length, j = m - 1, res[] = new int[n];\n        for (int i = 0; i < n; ++i) {\n            while (j >= 0 && 1L * spells[i] * potions[j] >= success)\n                j--;\n            count.put(spells[i], m - j - 1);\n        }\n        for (int i = 0; i < n; ++i) {\n            res[i] = count.get(spells0[i]);\n        }\n        return res;\n    }\n```
['C', 'Python', 'Java']