using System.Collections;
using System.Collections.Generic;
public static void Main()
int [] arrayTest1 = new int[]{-5, 7, 5, 4, -7, -1, 10};
public List<Sol> Test(int[] array, int nbRef)
int arrayLenght = array.Length;
List<Sol> solutions = new List<Sol>();
if (array != null && arrayLenght != 0)
for (indexDebut = 0; indexDebut < arrayLenght; indexDebut++)
for (indexFin = indexDebut + 1; indexFin < arrayLenght; indexFin++)
Sol sol = new Sol(indexDebut, indexFin, nbRef, array.ToList());
IComparer comparer = new BestSolComparer();
return solutions.OrderByDescending(x => x, comparer).ToList<Sol>();
public int IndexDebut { get; set; }
public int IndexFin { get; set; }
public int NbRef { get; set; }
List<int> Numbers = new List<int>();
get { return (IndexFin - IndexDebut) + 1 ;}
public Sol(int indexDebut, int indexFin, int nbRef, List<int> numbers)
return NbRef - (Numbers.Take(Numbers.Count).Sum());
public class BestSolComparer: IComparer
public int Compare(Object x, Object y)