Description
Submission
class Solution { public: int kthSmallest(vector<vector<int>>& mat, int k) { vector<int> v{0}; vector<int> tmp; for(auto& row: mat) { tmp.clear(); for(auto e: row) { for(auto x: v) { tmp.push_back(e+x); } } sort(tmp.begin(), tmp.end()); tmp.resize(min(k, (int)tmp.size())); v = tmp; } return v[k-1]; } };