using System.Numerics; public class Program { public static void Main() { //int num = int.Parse(Console.ReadLine() ?? string.Empty); string[] str = (Console.ReadLine() ?? string.Empty).Trim().Split(' '); string[] str2 = (Console.ReadLine() ?? string.Empty).Trim().Split(' '); //string color = Console.ReadLine() ?? string.Empty; int need = int.Parse(str[1]); int[] ints = new int[str2.Length]; for (int i = 0; i < str2.Length; i++) { if (int.Parse(str2[i]) < 0) { continue; } ints[i] = int.Parse(str2[i]); } Array.Sort(ints); int count = 0; for (int i = need; i > 0; i--) { if (i > ints.Length - 1 || ints[i] < 0) { break; } count += ints[i]; } Console.WriteLine(count); } }