fork download
  1. using static IO;
  2. public class IO {
  3. public static IO Cin = new();
  4. public static StreamReader reader = new(Console.OpenStandardInput());
  5. public static StreamWriter writer = new(Console.OpenStandardOutput());
  6. public static implicit operator string(IO _) => reader.ReadLine();
  7. public static implicit operator char[](IO _) => reader.ReadLine().ToArray();
  8. public static implicit operator int(IO _) => int.Parse(reader.ReadLine());
  9. public static implicit operator double(IO _) => double.Parse(reader.ReadLine());
  10. public static implicit operator string[](IO _) => reader.ReadLine().Split();
  11. public static implicit operator int[](IO _) => Array.ConvertAll(reader.ReadLine().Split(), int.Parse);
  12. public void Deconstruct(out int a, out int b) { int[] r = Cin; (a, b) = (r[0], r[1]); }
  13. public void Deconstruct(out int a, out int b, out int c) { int[] r = Cin; (a, b, c) = (r[0], r[1], r[2]); }
  14. public static void Loop(int end, Action<int> action, int start = 0, in int add = 1) { for (; start < end; start += add) action(start); }
  15. public static object? Cout { set { writer.Write(value); } }
  16. public static object? Coutln { set { writer.WriteLine(value); } }
  17. public static void Main() { Program.Coding(); writer.Flush(); }
  18. }
  19. class Program {
  20. public static void Coding() {
  21. checked {
  22. (int l,int w,int h) = Cin;
  23. int[] boxes = new int[21];
  24. Loop(Cin, _ => {
  25. (int pow, int count) = Cin;
  26. boxes[pow] = count;
  27. });
  28. int total = boxes.Sum();
  29.  
  30. long repay = 0, result = 0;
  31. for(int pow=19;pow>=0;pow--) {
  32. int shift = 1 << pow;
  33. long debt = (long)(l / shift) * (w / shift) * (h / shift);
  34. long used = Math.Min(debt - repay, boxes[pow]);
  35. result += used;
  36.  
  37. repay = (repay + used) * 8;
  38. }
  39.  
  40. if (l * w * h > repay / 8) {
  41. Cout = -1;
  42. return;
  43. }
  44.  
  45. Cout = result;
  46. }
  47. }
  48. }
Success #stdin #stdout 0.05s 30576KB
stdin
37 42 59
6
0 143821
1 14382
2 1438
3 143
4 14
5 1
stdout
5061