#include #include #include using namespace std; void findMinNumbers(vector> matrix, int n) { vector allElements; for (auto row : matrix) { for (int num : row) { allElements.push_back(num); } } sort(allElements.begin(), allElements.end()); vector minNumbers(allElements.begin(), allElements.begin() + n); for (int i = 0; i < n; i++) { cout << minNumbers[i] << " "; if ((i + 1) % 3 == 0) cout << endl; } } int main() { vector> matrix = { {2, 4, 6}, {8, 10, 12}, {14, 16, 18} }; int n = 5; findMinNumbers(matrix, n); return 0; }