~/algor $ cat problems/matritsa-qatorlarni-saralash
Sort rows by sum
Medium
1000 ms
128 MB
49%
An integer matrix of size $n \times m$ is given. Sort its rows in increasing order of the sums of their elements and print the matrix. Rows with equal sums keep their original order.
Input
The first line contains two positive integers $n$ and $m$. Each of the next $n$ lines contains $m$ integers.
Output
$n$ lines with $m$ space-separated integers each.
Note
$1 \le n, m \le 200$
$-1000 \le a_{i,j} \le 1000$
Examples
Input #1
3 2 5 5 1 2 0 3
Output #1
1 2 0 3 5 5
Input #2
2 2 1 1 2 0
Output #2
1 1 2 0