class Program { static void Main(string[] args) { string[] topInput = Console.ReadLine()!.Split(' '); int total = int.Parse(topInput[1]); string[] bottomInput = Console.ReadLine()!.Split(" "); List numList = new List(); for (int i = 0; i < bottomInput.Length; i++) { numList.Add(int.Parse(bottomInput[i])); } numList.Sort(); int max = numList[numList.Count - 1]; for (int i = 1;i < total;i++) { if (max < max + numList[numList.Count - 1 - i]) { max = max + numList[numList.Count - 1 - i]; } } Console.WriteLine(max); } }