using System; using System.Linq; namespace TestBench { internal class Program { public static int Val { get; set; } = 100; internal static void Main() { var l = int.Parse(Console.ReadLine()); Console.ReadLine(); var w = Console.ReadLine() .Split(' ') .Select(x => short.Parse(x)) .OrderBy(x => x) .Select((width, index) => new {width, index}).ToArray(); var accum = 0; var idx = 0; foreach (var elem in w) { var tmp = accum + elem.width; idx = elem.index; if (tmp > l) { break; } accum = tmp; } Console.WriteLine(idx); } } }