很典型的二分答案的题目 码着
#include<iostream> #include<algorithm> #include<string> #include<string.h> typedef long long ll; using namespace std; const int MAX = 5e4 + 5; ll n, k, a[MAX], b[MAX]; bool C(ll mid) { ll j = n, cnt = 0; for (ll i = 1; i <= n; i++) { while (j > 0) { if (a[i] * b[j] > mid) j--; else break; } cnt += j; } return cnt >= k; } int main() { ios::sync_with_stdio(false); cin >> n >> k; k = n*n - k+1; for (int i = 1; i <= n; i++) cin >> a[i]>> b[i]; sort(a+1, a + n+1); sort(b+1, b + n+1); ll l = a[1] * b[1], r = a[n] * b[n]; for(int i=0;i<100;i++) { ll mid = (l + r) >> 1; if (C(mid)) r = mid; else l = mid; } cout << r << endl; return 0; }