{-# LANGUAGE MultiParamTypeClasses,FlexibleContexts,FlexibleInstances,TypeSynonymInstances,BangPatterns,RankNTypes,TupleSections #-} import Control.Monad import Control.Monad.ST import Control.Applicative import Control.Arrow import Debug.Trace import Text.Printf import Data.List hiding(insert) import Data.Int import Data.Bits import Data.Maybe import Data.Monoid import Data.Array.Unboxed import Data.Array.ST import qualified Data.Map as M import qualified Data.Set as S import qualified Data.ByteString.Char8 as B readInt = fromJust . fmap fst . B.readInt readInts = map readInt . B.words <$> B.getLine readIntPair = l2p . map readInt . take 2 . B.words <$> B.getLine readLns :: Read a => IO [a] readLns = map read . words <$> getLine cmpFst (a,_) (b,_) = compare a b cmpSnd (_,a) (_,b) = compare a b cmpLen a b = length a `compare` length b swap (a,b) = (b,a) l2p (a:b:_) = (a,b) p2l (a,b) = [a,b] itof :: Int -> Double itof = fromIntegral defaultArray :: (IArray a e,Ix i) => e -> (i,i) -> [(i,e)] -> a i e defaultArray = accumArray $ curry snd flatten :: [(a,[(b,c)])] -> [((a,b),c)] flatten = (=<<) $ uncurry $ fmap . first . (,) stepM_ :: Monad m => a -> (a -> Bool) -> (a -> a) -> (a -> m ()) -> m () stepM_ i judge incr step = sub i where sub i | judge i = step i >> sub (incr i) | otherwise = return () thru :: Monad m => (v -> m ()) -> v -> m v thru m v = m v >> return v inf = maxBound `div` 2 :: Int main = do n <- readLn :: IO Int ps <- map ((/1000).itof)<$> readInts qs <- map ((/100).itof) <$> readInts let go !e c queue | c > 3000 * n = e | otherwise = let (p,q) = minElem queue in let queue' = insert (p * (1 - q)) q $ deleteMin queue in go (e - p * itof c) (c+1) queue' let p0 = map negate $ zipWith (*) ps qs let q0 = foldr (uncurry insert) emptyHP $ zip p0 qs printf "%.5f\n" $ go 0 1 q0 data Heap k v = Null | Fork !k !v !(Heap k v) !(Heap k v) {-# INLINE emptyHP #-} emptyHP :: Heap k v emptyHP = Null {-# INLINE isEmpty #-} isEmpty :: Heap k v -> Bool isEmpty Null = True isEmpty _ = False {-# INLINE minElem #-} minElem :: Heap k v -> (k,v) minElem (Fork k v _ _) = (k,v) minElem Null = error "min for empty queue is not supported" {-# INLINE minKey #-} minKey :: Heap k v -> k minKey (Fork k _ _ _) = k minKey Null = error "min for empty queue is not supported" {-# INLINE deleteMin #-} deleteMin :: (Ord k) => Heap k v -> Heap k v deleteMin (Fork _ _ a b) = merge a b deleteMin _ = undefined {-# INLINE merge #-} insert :: (Ord k) => k -> v -> Heap k v -> Heap k v insert k v a = merge (Fork k v Null Null) a merge :: (Ord k) => Heap k v -> Heap k v -> Heap k v merge a Null = a merge Null b = b merge a b | minKey a <= minKey b = jo a b | otherwise = jo b a where jo (Fork k v _a _b) _c = Fork k v _b (merge _a _c) jo _ _ = undefined