C++ | Binary Search | O(nlogn) | dangerous
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(nlogn)$$\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# Code\n```\nclass Solution {\npublic:\n    long long kthSmallestProduct(vector<int>& nums1, vector<int>& nums2, long long k) {\n        vector<int> pos, neg, pos1, neg1;\n        int zero = 0, zero1 = 0;\n        for (int &x: nums1) {\n            if (x == 0) {\n                zero++;\n            } else if (x > 0) {\n                pos.push_back(x);\n            } else {\n                neg.push_back(x);\n            }\n        }\n        for (int &x: nums2) {\n            if (x == 0) {\n                zero1++;\n            } else if (x > 0) {\n                pos1.push_back(x);\n            } else {\n                neg1.push_back(x);\n            }\n        }\n        \n        int psz = pos.size(), nsz = neg.size(), psz1 = pos1.size(), nsz1 = neg1.size();\n        long long totalZero = 1LL * (psz + nsz) * zero1 + 1LL * (psz1 + nsz1) * zero + 1LL * zero * zero1;\n\n        auto getPosPos = [&](long long p) -> long long {\n            if (p <= 0) return 0;\n            int i = 0, j = psz1 - 1;\n            long long cnt = 0;\n\n            while (i < psz && j >= 0) {\n                while (j >= 0 && 1LL * pos[i] * pos1[j] > p) {\n                    j--;\n                }\n                cnt += j + 1;\n                i++;\n            }\n            return cnt;\n        };\n\n        auto getPosNeg = [&](long long p) -> long long {\n            if (p >= 0) return 1LL * psz * nsz1;\n            long long cnt = 0;\n            int i = 0, j = 0;\n            while (i < nsz1 && j < psz) {\n                while (j < psz && 1LL * neg1[i] * pos[j] > p) {\n                    j++;\n                }\n                cnt += psz - j;\n                i++;\n            }\n            return cnt;\n        };\n\n        auto getNegPos = [&](long long p) -> long long {\n            if (p >= 0) return 1LL * nsz * psz1;\n            long long cnt = 0;\n            int i = 0, j = 0;\n            while (i < nsz && j < psz1) {\n                while (j < psz1 && 1LL * neg[i] * pos1[j] > p) {\n                    j++;\n                }\n                cnt += psz1 - j;\n                i++;\n            }\n            return cnt;\n        };\n\n        auto getNegNeg = [&](long long p) -> long long {\n            if (p <= 0) return 0;\n            int i = nsz - 1, j = 0;\n            long long cnt = 0;\n            while (i >= 0 && j < nsz1) {\n                while (j < nsz1 && 1LL * neg[i] * neg1[j] > p) {\n                    j++;\n                }\n                cnt += nsz1 - j;\n                i--;\n            }\n            return cnt;\n        };\n\n        auto getCount = [&](long long p) -> long long {\n            long long cnt = getPosPos(p) + getPosNeg(p) + getNegPos(p) + getNegNeg(p);\n            if (p >= 0) {\n                cnt += totalZero;\n            }\n            return cnt;\n        };\n        \n        long long lo = -1e11, hi = 1e10;\n        // smallest product whose count is >= k, where count is number of products in num1 * nums2 that are less than equal to given product\n        while (lo < hi) {\n            long long mid = lo + (hi - lo) / 2; // hi is always valid / true. Extend the valid region to the left\n            if (getCount(mid) >= k) {\n                hi = mid;\n            } else {\n                lo = mid + 1;\n            }\n        }\n        return lo;\n    }\n};\n```
['C++']