c++ solution using binary search
\nclass Solution {\npublic:\n    int n,m;\n    using ll =long long;\n    ll find(vector<int>&nums1,vector<int>&nums2,ll product)\n    {\n        ll count=0;\n  
```\nclass Solution {\npublic:\n    int n,m;\n    using ll =long long;\n    ll find(vector<int>&nums1,vector<int>&nums2,ll product)\n    {\n        ll count=0;\n        for(int i=0;i<n;i++)\n        {\n            long long val=nums1[i];\n             if(val>=0)\n            {\n                ll l=0;\n                ll r=m-1;\n                ll ans=-1;\n                while(l<=r)\n                {\n                    ll mid=(l+r)/2;\n                    if((val*nums2[mid])<=product)\n                    {\n                        ans=mid;\n                        l=mid+1;\n                    }\n                    else\n                    {\n                        r=mid-1;\n                    }\n                }\n                count+=ans+1;\n            }\n            else\n            {\n                ll l=0;\n                ll r=m-1;\n                ll ans=m;\n                while(l<=r)\n                {\n                    ll mid=(l+r)/2;\n                    if((val*nums2[mid])<=product)\n                    {\n                        ans=mid;\n                        r=mid-1;\n                    }\n                    else\n                    {\n                        l=mid+1;\n                    }\n                }\n                count+=m-ans;\n            }\n        }\n        return count;\n    }\n    long long kthSmallestProduct(vector<int>& nums1, vector<int>& nums2, long long k) \n    {\n        n=nums1.size();\n        m=nums2.size();\n        ll f1=nums1[0];\n        ll f2=nums1[n-1];\n        ll f3=nums2[0];\n        ll f4=nums2[m-1];\n        ll l=min({f1*f2,f1*f3,f1*f4,f2*f3,f2*f4,f3*f4});\n        ll r=max({f1*f2,f1*f3,f1*f4,f2*f3,f2*f4,f3*f4});\n        ll ans=-1;\n        while(l<=r)\n        {\n            ll mid=(l+r)/2;\n            if(find(nums1,nums2,mid)>=k)\n            {\n                ans=mid;\n                r=mid-1;\n            }\n            else\n            {\n                l=mid+1;\n            }\n        }\n        return ans;\n    }\n};\n```
['C', 'Binary Tree', 'C++']