#include #include #include std::vector> getLargestMatrix(const std::vector>& matrix, const std::vector& extraNums) { std::vector combined; // Flatten the 4x4 matrix into a 1D vector for (const auto& row : matrix) { for (int num : row) { combined.push_back(num); } } // Add extra numbers to the list combined.insert(combined.end(), extraNums.begin(), extraNums.end()); // Sort the combined numbers in descending order std::sort(combined.rbegin(), combined.rend()); // Take the largest 16 elements and form a new 4x4 matrix std::vector> newMatrix(4, std::vector(4)); for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) newMatrix[i][j] = combined[i * 4 + j]; return newMatrix; } int main() { // Input 4x4 matrix std::vector> matrix = { {2, 4, 6, 8}, {10, 12, 14, 16}, {18, 19, 20, 22}, {24, 26, 28, 30} }; // Input additional numbers (19, 17, 15, 13) std::vector extraNums = {19, 17, 15, 13}; // Get new matrix with the largest numbers std::vector> newMatrix = getLargestMatrix(matrix, extraNums); // Output the new matrix for (const auto& row : newMatrix) { for (int num : row) { std::cout << num << " "; } std::cout << std::endl; } return 0; }