# Problem Description
This is a geometric problem involving clock hand movements and distance calculations. We need to:
1. Start with an initial time (h:m) and two arrows of lengths a and b
2. After k minutes, calculate the length of a line that connects:
   - The initial position of the hour hand
   - The final position of the minute hand
3. Return this length rounded to 2 decimal places

# Visual Facts
1. Two example scenarios are shown:
   - Scenario 1: 3:00 → 3:40 (40 min progression)
   - Scenario 2: 4:20 → 5:30 (70 min progression)

2. Each clock shows:
   - Orange arrow (hour hand)
   - Green arrow (minute hand)
   - Red dashed line (the target distance we need to calculate)

3. Clock face components:
   - 12 major marks (hours)
   - 360 degrees total
   - Center point where hands meet

# Visual Patterns
1. Hand Movement Patterns:
   - Hour hand makes a complete 360° rotation in 12 hours (30° per hour)
   - Minute hand makes a complete 360° rotation in 60 minutes (6° per minute)
   - Hour hand moves proportionally between hours (0.5° per minute)

2. Geometric Relationships:
   - Red dashed line forms a triangle with:
     * Initial hour hand position (fixed)
     * Final minute hand position (after k minutes)
     * Center point of the clock

3. Calculation Pattern:
   - We need to use trigonometry to find the length of the red line
   - The angle between initial and final positions can be calculated using:
     * Initial hour position (h * 30 + m * 0.5 degrees)
     * Final minute position ((m + k) * 6 degrees)

4. Triangle Solution Pattern:
   - The red line length can be found using the law of cosines:
   ```
   red_length = √(a² + b² - 2ab * cos(θ))
   ```
   where θ is the angle between the initial hour position and final minute position

# Solution
import math

def solution(h: int, m: int, a: int, b: int, k: int) -> float:
    """
    Given an initial time (in 12-hour format) and the lengths of the orange and green arrows, calculate the length of the red dashed line after k minutes

    Parameters:
        h (int): Hour.
        m (int): Minute.
        a (int): Length of the orange arrow.
        b (int): Length of the green arrow.
        k (int): Duration passed (in minutes).

    Returns:
        float: Length of the red dashed line (rounded to two decimal places).
    """
    # Calculate the new time
    total_minutes = h * 60 + m + k
    new_m = total_minutes % 60
    
    # Calculate the angles
    minute_angle = new_m * 6  # 6 degrees per minute
    hour_angle = (h % 12) * 30 + m * 0.5  # 30 degrees per hour + 0.5 degrees per minute
    
    # Convert angles to radians
    minute_angle_rad = math.radians(minute_angle)
    hour_angle_rad = math.radians(hour_angle)
    
    # Convert to Cartesian coordinates
    minute_x = b * math.cos(minute_angle_rad)
    minute_y = b * math.sin(minute_angle_rad)
    hour_x = a * math.cos(hour_angle_rad)
    hour_y = a * math.sin(hour_angle_rad)
    
    # Calculate the distance between the two points
    distance = math.sqrt((minute_x - hour_x) ** 2 + (minute_y - hour_y) ** 2)
    
    return round(distance, 2)


# Test Script
def test():
    test_cases = [
        (3, 0, 3, 4, 40, 6.77),
        (3, 0, 4, 3, 180, 5.0),
        (3, 0, 2, 7, 40, 8.79),
        (4, 20, 6, 8, 70, 6.19),
        (6, 0, 6, 8, 150, 2),
        (8, 22, 5, 9, 137, 4.46),
        (7, 12, 4, 6, 29, 3.23),
        (1, 56, 2, 7, 173, 8.29),
        (1, 56, 3, 4, 104, 7.0),
        (0, 56, 3, 4, 84, 5.08),
    ]

    for h, m, a, b, k, expected_output in test_cases:
        try:
            output = solution(h, m, a, b, k)
        except Exception as e:
            error_message = (
                f"An exception occurred while running the test case:\n"
                f"`h`: {h}\n"
                f"`m`: {m}\n" 
                f"`a`: {a}\n"
                f"`b`: {b}\n"
                f"`k`: {k}\n\n"
                f"Exception: '{str(e)}'"
            )
            assert False, error_message

        if output != expected_output:
            error_message = (
                f"The following Test Case failed:\n"
                f"`h`: {h}\n"
                f"`m`: {m}\n"
                f"`a`: {a}\n"
                f"`b`: {b}\n"
                f"`k`: {k}\n\n"
                f"Actual Output: {output}\n"
                f"Expected Output: {expected_output}"
            )
            assert False, error_message

test()