sawczakl

ccc 2025 senior 1

Feb 11th, 2026 (edited)
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.49 KB | None | 0 0
  1. # First sample problem here
  2. # https://cemc.uwaterloo.ca/sites/default/files/documents/2025/2025CCCSrProblems.html
  3.  
  4. # Input is a set of four space-separated integers, e.g. 1 2 3 4
  5. # Order: painting 1's base and height, then painting 2's base and height
  6. values = input()
  7. A, B, X, Y = (int(v) for v in values.split())
  8.  
  9. # Thinking through this...
  10. # Evidently, the minimum area is when the paintings directly abut each other, with no gap in between.
  11. # Moreover, it'll be optimal if one painting is entirely contained in one dimension of the other rectangle, either length or height (that is, they don't just touch at the corners or something).
  12.  
  13. # The optimal wall coverage will thus be the LONGEST dimension on one axis (the longer base or height), and the SUM of the dimensions on the other axis. See example #3 in the problem PDF for why this is the case. There, the rectangle is painting 2's base (3) by the combined heights of the paintings (1 + 2).
  14.  
  15. # We can just try making both arrangements (stack them horizontally or vertically) and see which is shorter, then output that.
  16. # Note that they can't rotate, so we only need to compare base to base and height to height, not other combinations of those.
  17.  
  18. stack_bases = max(A, X) + B + Y
  19. stack_heights = max(B, Y) + A + X
  20.  
  21. # Find the smaller way of stacking them
  22. smaller = min((stack_bases, stack_heights))
  23.  
  24. # Don't forget that we only found one of each dimension (how tall and how wide it has to be)
  25. # So double it for the perimeter
  26. print(2 * smaller)
Advertisement
Add Comment
Please, Sign In to add comment