using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; // No.5 数字のブロック // http://yukicoder.me/problems/14 class Program { static void Main(string[] args) { //var In = new StreamReader("C:\\Users\\tny2\\Desktop\\14-testcase\\test_in\\4.txt"); var In = Console.In; var L = int.Parse(In.ReadLine()); var N = int.Parse(In.ReadLine()); var Wn = In.ReadLine() .Split(' ') .Select(w => int.Parse(w)) .OrderBy(w => w) .ToArray(); //-------------------------------------------- // Nっていつも使わないなあ、と思うのはC#erだけなのだろうか。 //-------------------------------------------- // E | W T | S // ---------------- // 1 | 1 1 | 1 // 2 | 2 3 | 1 2 // 3 | 3 6 | 1 2 3 // 4 | 4 10 | 1 2 3 4 var E = Enumerable.Range(0, Wn.Count()); var S = E.Select(e => Wn.Take(e)); // var V = T.Where(t => t <= L).Count(); var length = 0; var n = 0; foreach( var e in E ) { length += Wn[e]; if (length > L) break; n++; } Console.WriteLine(n); } }