Skip to content

Instantly share code, notes, and snippets.

@l4u
Created April 18, 2014 11:07
Show Gist options
  • Save l4u/11038091 to your computer and use it in GitHub Desktop.
Save l4u/11038091 to your computer and use it in GitHub Desktop.
import Debug.Trace
import Control.Monad
import Data.List
getInt::IO Integer
getInt = do
s <- getLine
return (read s)
pro :: [Integer] -> Integer -> Integer -> Integer -> Integer
pro [] m s c
| s >= m = c
| otherwise = -1
pro (l:ls) m s c
| s >= m = c
| otherwise = pro ls m (s+l) (c+1)
main :: IO ()
main = do
_ <- getInt
l <- fmap ((map read) . words) getLine :: IO [Integer]
let sortL = sortBy (flip compare) l
print (pro [5,4,3,2,1] 15 0 0)
t <- liftM read getLine
replicateM_ t (do
i <- getInt
print (pro sortL i 0 0)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment