using System; using System.Linq; class Program { static void Main() { /// 16 : 規定箱の幅 /// 3 : 挿入箱の数 /// 10 5 7 : 挿入箱の幅 // 標準入力 var spfBox = int.Parse(Console.ReadLine()); var boxCnt = int.Parse(Console.ReadLine()); var aryBox = Console.ReadLine().Split().Select(int.Parse).ToArray(); // 配列を降順でソート Array.Sort(aryBox); // 空変数定義 var ansBox = 0; var ansCnt = 0; // 変数に最小値から代入し規定値を超えていないかチェック for (var i = 0; i < boxCnt; i++) { if ((ansBox += aryBox[i]) > spfBox) break; else ansCnt++; } Console.WriteLine(ansCnt); } }