fork download
  1. using System.Reflection.Metadata;
  2. using static IO;
  3. public class IO
  4. {
  5. public static IO Cin = new();
  6. public static StreamReader reader = new(Console.OpenStandardInput());
  7. public static StreamWriter writer = new(Console.OpenStandardOutput());
  8. public static implicit operator string(IO _) => reader.ReadLine();
  9. public static implicit operator char[](IO _) => reader.ReadLine().ToArray();
  10. public static implicit operator int(IO _) => int.Parse(reader.ReadLine());
  11. public static implicit operator double(IO _) => double.Parse(reader.ReadLine());
  12. public static implicit operator string[](IO _) => reader.ReadLine().Split();
  13. public static implicit operator int[](IO _) => Array.ConvertAll(reader.ReadLine().Split(), int.Parse);
  14. public void Deconstruct(out int a, out int b) { int[] r = Cin; (a, b) = (r[0], r[1]); }
  15. public void Deconstruct(out int a, out int b, out int c) { int[] r = Cin; (a, b, c) = (r[0], r[1], r[2]); }
  16. public static void Loop(int end, Action<int> action, int start = 0, in int add = 1) { for (; start < end; start += add) action(start); }
  17. public static object? Cout { set { writer.Write(value); } }
  18. public static object? Coutln { set { writer.WriteLine(value); } }
  19. public static void Main() { Program.Coding(); writer.Flush(); }
  20. }
  21. class Program
  22. {
  23. public static void Coding()
  24. {
  25. checked
  26. {
  27. (int n, int m) = Cin;
  28. PriorityQueue<int, int> sockets = new();
  29. Loop(m, _ => sockets.Enqueue(0, 0));
  30.  
  31. foreach (int time in (int[])Cin)
  32. {
  33. int used = time + sockets.Dequeue();
  34. sockets.Enqueue(used, used);
  35. }
  36.  
  37. int maximum = 0;
  38. while (sockets.Count > 0) maximum = Math.Max(maximum, sockets.Dequeue());
  39.  
  40. Cout = maximum;
  41. }
  42. }
  43. }
Success #stdin #stdout 0.08s 32892KB
stdin
5 2
1 4 4 8 1
stdout
12