#include <iostream>
#include <array>
#include <algorithm>
#include <cstddef>

template <typename T, std::size_t R, std::size_t C>
using Matrix = std::array<std::array<T, C>, R>;

int main() {
    Matrix<int, 3, 3> matrix = {{ { 2, 3, 4 },
                                  { 7, 8, 9 },
                                  { 5, 6, 7 } }};

    std::sort(std::begin(matrix), std::end(matrix), [] (decltype(*matrix.cbegin())& lhs, decltype(*matrix.cbegin())& rhs) {
        return std::accumulate(std::begin(lhs), std::end(lhs), 0) > std::accumulate(std::begin(rhs), std::end(rhs), 0);
    });

    for (decltype(matrix.size()) row = 0; row != matrix.size(); ++row) {
        std::cout << row + 1 << ". ";
        for (const auto i : matrix[row]) {
            std::cout << i << " ";
        }
        std::cout << std::accumulate(std::begin(matrix[row]), std::end(matrix[row]), 0) << std::endl;
    }
}
