Sort by

recency

|

931 Discussions

|

  • + 0 comments

    Here is my simple c++ solution, you can watch the explanation here : https://youtu.be/T9sxEzAbp-M

    long taumBday(int b, int w, int bc, int wc, int z) {
        long bp = min(bc, wc + z);
        long wp = min(wc, bc + z);
        return bp * b + wp * w;
    }
    
  • + 1 comment

    This is my code in C#

        public static long taumBday(int b, int w, int bc, int wc, int z)
        {
            long normalCost = (long)b * bc + (long)w * wc;
            long alternativeCost1 = (long)b * bc + (long)w * (bc + z);
            long alternativeCost2 = (long)w * wc + (long)b * (wc + z);
            return Math.Min(normalCost, Math.Min(alternativeCost1, alternativeCost2));
        }
    
  • + 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
    
  • + 0 comments
    def taumBday(b, w, bc, wc, z):
        # Write your code here
        res= (w*wc) + (b*bc)
        should_convert = z < abs(bc-wc)
        if should_convert:
            if bc-wc > 0:
                bc = wc+z
                return (w*wc) + (b*bc)
            if wc-bc > 0:
                wc = bc+z
                return (w*wc) + (b*bc)  
        return res
    
  • + 1 comment

    This want me to return number but in typescript number have limit so there is noway to return it (or idk the way). Example must return 617318315833461267, the number reduce to 617318315833461200 make my answer wrong