using System.Collections.Generic;
public static int[] KWeakestRows(int[][] mat, int k)
var listSumSoldiersInRow = new Dictionary<int, int>();
for (var i = 0; i < mat.Length; i++)
for (var j = 0; j < mat[i].Length; j++)
sumSoldiers += mat[i][j];
listSumSoldiersInRow.Add(i, sumSoldiers);
var sortedListSumSoldiersInRow = listSumSoldiersInRow.OrderBy(v => v.Value);
var indices = new int[k];
for (var y = 0; y < k; y++)
indices[y] = sortedListSumSoldiersInRow.ElementAt(y).Key;
public static void Main()
var test = new int [][] {
var weakestRowsIndices = KWeakestRows(test, 5);
foreach (var row in weakestRowsIndices)