{-# LANGUAGE NumericUnderscores #-} {-# LANGUAGE TupleSections #-} import Control.Arrow import qualified Data.ByteString.Char8 as BSC8 import qualified Data.Vector.Unboxed as VU ------------------------------------------------------------------------------- -- input ------------------------------------------------------------------------------- type Parser a = BSC8.ByteString -> Maybe (a, BSC8.ByteString) parseInt :: Parser Int parseInt = fmap (second BSC8.tail) . BSC8.readInt parseM :: Int -> IO (VU.Vector Int) parseM m = VU.unfoldrN m parseInt <$> BSC8.getLine ------------------------------------------------------------------------------- -- Bucket Sort ------------------------------------------------------------------------------- bucketSortVU :: Int -> VU.Vector Int -> VU.Vector Int bucketSortVU bucketSize = VU.concatMap (uncurry $ flip VU.replicate) . VU.indexed . VU.unsafeAccumulate (+) (VU.replicate bucketSize 0) . VU.map (, 1) {-# INLINE bucketSortVU #-} ------------------------------------------------------------------------------- -- main ------------------------------------------------------------------------------- main :: IO () main = do l <- readLn :: IO Int m <- readLn :: IO Int ws <- parseM m print . VU.length . VU.takeWhile (<= l) . VU.scanl1 (+) . bucketSortVU 10_000 $ ws