using System; using System.Collections.Generic; using System.Linq; namespace PracticeAtCoder { class Program { static void Main(string[] args) { //ブロック string sA = Console.ReadLine(); string sB = Console.ReadLine(); string sC = Console.ReadLine(); string[] sD = sC.Split(' '); int[] after = sD.Select(s => int.Parse(s)).ToArray(); Array.Sort(after); int intSA = int.Parse(sA); int intSB = int.Parse(sB); int i = 0; int sumA = 0; //While文に書き直して判断を行う while(i < intSB && sumA + after[i] <= intSA){ sumA = sumA + after[i]; i++; } Console.WriteLine(i); } } }