0786.cpp (526B)
1 class Solution { 2 public: 3 vector<int> kthSmallestPrimeFraction(const vector<int> &arr, int k) const { 4 priority_queue<tuple<double, int, int>> pq; 5 6 for (int i = 0; i < arr.size(); i++) { 7 pq.emplace(-1.0 * arr[i] / arr.back(), i, arr.size() - 1); 8 } 9 10 while (true) { 11 auto [_, i, j] = pq.top(); 12 pq.pop(); 13 if (!--k) return {arr[i], arr[j]}; 14 if (--j > i) pq.emplace(-1.0 * arr[i] / arr[j], i, j); 15 } 16 17 return {}; 18 } 19 };