using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "Input5"; static List GetInputList() { var WillReturn = new List(); if (InputPattern == "Input1") { WillReturn.Add("3 2"); WillReturn.Add("1 2 3"); //1 } else if (InputPattern == "Input2") { WillReturn.Add("3 2"); WillReturn.Add("1 1 3"); //2 } else if (InputPattern == "Input3") { WillReturn.Add("4 10"); WillReturn.Add("3 2 4 1"); //4 } else if (InputPattern == "Input4") { WillReturn.Add("6 257109"); WillReturn.Add("53771 46578 31908 80435 62678 4327"); //5 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List InputList = GetInputList(); int M = InputList[0].Split(' ').Select(X => int.Parse(X)).Last(); int[] CArr = InputList[1].Split(' ').Select(X => int.Parse(X)).ToArray(); Array.Sort(CArr); int TatalCnt = 0; for (int I = 0; I <= CArr.GetUpperBound(0); I++) { TatalCnt += CArr[I]; if (TatalCnt > M) { Console.WriteLine(I); break; } else if (TatalCnt == M) { Console.WriteLine(I + 1); break; } } } }