Skip to content

Instantly share code, notes, and snippets.

@myuon
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save myuon/e4135f421551106f155d to your computer and use it in GitHub Desktop.

Select an option

Save myuon/e4135f421551106f155d to your computer and use it in GitHub Desktop.
paiza Online Hackathon
問題: https://paiza.jp/poh/kirishima
結果: http://paiza.jp/poh/kirishima/result/c7b9268a3c4b60e5c40aff903b3b9d96
import Control.Applicative
import Data.List
import qualified Data.IntMap as IM
import Data.Ord
solve :: Int -> [[Int]] -> Int
solve n ps = getMin $ IM.assocs $ iter ps $ IM.singleton 0 0 where
iter [] m = m
iter (p:ps) m = iter ps $ IM.foldrWithKey' (go p) m m
go [x,y] a b m = if a>=n then m else IM.insertWith' min (a+x) (y+b) m
getMin ns = minimum [y|(x,y)<-ns, x>=n]
main = do
m <- (read :: String -> Int) <$> getLine
_ <- getLine
ns <- fmap (fmap (read :: String -> Int) . words) . lines <$> getContents
print $ solve m ns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment