c++ | binary search | easy to understand
\n# Code\n\nclass Solution {\npublic:\n    bool check(long long midval,vector<int>& nums1, vector<int>& nums2, long long k){\n        long long cnt=0;\n        
\n# Code\n```\nclass Solution {\npublic:\n    bool check(long long midval,vector<int>& nums1, vector<int>& nums2, long long k){\n        long long cnt=0;\n        for(int i=0;i<nums1.size();i++)\n        {\n            long long val=nums1[i];\n\t\t\tif(val==0 and midval>=0)\n                cnt+=nums2.size();\n            \n            else if(val>0)\n                cnt+=findmaxIndex(nums2,val,midval);\n            \n            else if(val<0)\n                cnt+=findminIndex(nums2,val,midval);\n        }\n        return cnt>=k;\n    }\n    \n    int findmaxIndex(vector<int>&nums2 , long long  val , long long midval)\n    {\n        int l = 0  , r = nums2.size()-1 , res=  -1;\n        while(l<=r)\n        {\n            long long mid = (l+r)/2;\n            if(val*nums2[mid]<=midval)\n            {\n                res=mid;\n                l=mid+1;\n            }\n            else r=mid-1;\n        }\n        return res+1;\n    }\n    \n    int findminIndex(vector<int>&nums2 , long long  val , long long midval)\n    {\n        int l = 0  , r = nums2.size()-1 , res=  r+1;\n        while(l<=r)\n        {\n            long long mid = (l+r)/2;\n            if(val*nums2[mid]<=midval)\n            {\n                res=mid;\n                r=mid-1;\n            }\n            else l=mid+1;\n        }\n        return nums2.size()-res;\n    }\n    \n    long long kthSmallestProduct(vector<int>& nums1, vector<int>& nums2, long long k) {\n        long long l=-1e10,r=1e10,res=-1;\n        while(l<=r){\n            long long mid = (l+r)/2;\n            if(check(mid,nums1,nums2,k)) {\n                res=mid;\n                r=mid-1;\n            }\n            else l=mid+1;\n        }\n        return res;\n    }\n};\n```
['C++']