fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public static void Main()
  6. {
  7. int test = Convert.ToInt32(Console.ReadLine());
  8. List<int> input = Console.ReadLine()
  9. .Split(' ') // Split input by spaces
  10. .Select(int.Parse) // Convert each part to an int
  11. .ToList(); // Store in a List<int>
  12. input.Sort();
  13. input.Reverse();
  14.  
  15. for (int i = 0; i < test; i++)
  16. {
  17.  
  18.  
  19. // Use a for loop to process the list
  20. for (int a = input.Count - 1; a > 0; a--)
  21. {
  22. // Combine the two smallest elements (last two in the sorted list)
  23. int combined = (input[a] + input[a - 1]) - 1;
  24.  
  25. // Remove the two smallest elements
  26. input.RemoveAt(a); // Remove last element
  27. input.RemoveAt(a - 1); // Remove second last element
  28.  
  29. // Add the combined value to the end of the list
  30. input.Add(combined);
  31.  
  32. // Re-adjust the loop variable `a` because the list size has changed
  33. a = input.Count; // Reset `a` to the new size of the list
  34. }
  35.  
  36.  
  37. }
  38. // Output the final remaining element
  39. Console.WriteLine(input[0]);
  40.  
  41. }
  42. }
  43.  
Success #stdin #stdout 0.06s 31508KB
stdin
3
998 244 353
stdout
1593