From 1738c67c2e0d4dfe5b61b09419f522f31ff8983f Mon Sep 17 00:00:00 2001 From: chayan das Date: Wed, 8 Oct 2025 13:09:23 +0530 Subject: [PATCH] Create 2300. Successful Pairs of Spells and Potions --- 2300. Successful Pairs of Spells and Potions | 27 ++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 2300. Successful Pairs of Spells and Potions diff --git a/2300. Successful Pairs of Spells and Potions b/2300. Successful Pairs of Spells and Potions new file mode 100644 index 0000000..a06743e --- /dev/null +++ b/2300. Successful Pairs of Spells and Potions @@ -0,0 +1,27 @@ +class Solution { +public: + #define ll long long + vector successfulPairs(vector& spells, vector& potions, long long success) { + sort(potions.begin(), potions.end()); + vector ans(spells.size()); + + for (int i = 0; i < spells.size(); i++) { + ll sp = spells[i]; + ll s = 0, e = potions.size() - 1; + int ind = -1; + + while (s <= e) { + int mid = (s + e) / 2; + if (potions[mid] * sp >= success) { + ind = mid; + e = mid - 1; + } else { + s = mid + 1; + } + } + + ans[i] = (ind == -1) ? 0 : (potions.size() - ind); + } + return ans; + } +};