1 class Solution 2 { 3 public: 4 int kthSmallest(vector<vector<int>>& matrix, int k) 5 { 6 priority_queue<int,vector<int>,greater<int>> pq; 7 int n = matrix.size(); 8 for(int i = 0;i < n;i ++) 9 { 10 for(int j = 0;j < n;j ++) pq.push(matrix[i][j]); 11 } 12 while(--k && !pq.empty()) pq.pop(); 13 return pq.top(); 14 } 15 };