using System; using System.Collections.Generic; public class InputStrorage { public long L; public long N; public long[] Array; } public static class InputHandler { public static void ReadInput(InputStrorage input) { string[] str = Console.ReadLine().Split(); input.L = int.Parse(str[0]); str = Console.ReadLine().Split(); input.N = int.Parse(str[0]); str = Console.ReadLine().Split(); input.Array = new long[input.N]; for(int i =0; i < input.N; i++) { input.Array[i] = long.Parse(str[i]); } } } namespace GeneralLibs { public class Compare { public static long ReturnMax(long a, long b) { if (a > b) return a; else return b; } public static long ReturnMax(long[] a) { long max = long.MinValue; for (int i = 0; i < a.Length; i++) { if (a[i] > max) max = a[i]; } return max; } } public class ShowValues { public static void ShowArray1D(long[] a, string str = "default") { Console.WriteLine(str); for (int i = 0; i < a.Length; i++) { Console.Write("{0} ", a[i]); } Console.WriteLine(); Console.WriteLine(str); } public static void ShowValue(long a, string str = "default") { Console.WriteLine("{0} : {1}", a, str); } } } public class SpecificLibs { } public class BinarySearch { public static long ReturnLowerBoundOfTarget(long[] array, long target) { long First = 0; long Mid = -1; long Last = array.Length - 1; while (First <= Last) { Mid = First + (Last - First) / 2; if (array[Mid] <= target) First = Mid + 1; else Last = Mid - 1; } return Last; } } public class PrefixSum { public static long[] ReturnPrefixSum1D(long[] input) { long n = input.Length; long[] output = new long[n + 1]; long sum = 0; output[0] = 0; for (long i = 1; i < n + 1; i++) { sum += input[i - 1]; output[i] = sum; } return output; } public static long ReturnSegmentValue(long[] input, long start, long end) { return input[end] - input[start - 1]; } } static class No5 { static void Main() { InputStrorage input = new InputStrorage(); InputHandler.ReadInput(input); Array.Sort(input.Array); long[] sum = new long[input.N + 1]; sum = PrefixSum.ReturnPrefixSum1D(input.Array); long target = BinarySearch.ReturnLowerBoundOfTarget(sum,input.L); Console.WriteLine(target); } }