• + 0 comments

    Haskell:

    module Main where
    
    import Control.Monad (replicateM_)
    
    solve :: Int -> Int -> Int -> Int -> Int -> Int
    solve b w bc wc z
        | bc > wc + z = (b + w) * wc + b * z
        | wc > bc + z = (b + w) * bc + w * z
        | otherwise = b * bc + w * wc
    
    main :: IO ()
    main = do
        cases <- readLn :: IO Int
        replicateM_ cases $ do
            [b, w] <- map read . words <$> getLine
            [bc, wc, z] <- map read . words <$> getLine
            print $ solve b w bc wc z