```
class Solution {
public:
int kthSmallest(vector<vector<int>>& matrix, int k) {
multiset<int> my_set;
for (auto vi : matrix) {
for (auto vj : vi) {
my_set.emplace(vj);
}
}
int result = 0;
for (auto l : my_set) {
if (k == 1) {
result = l;
}
-- k;
}
return result;
}
};
```

std::multiset is implement by rb_tree. So these element in the tree would be sorted by key, which is exactly what we want.