Last active
August 29, 2015 14:04
-
-
Save myuon/e4135f421551106f155d to your computer and use it in GitHub Desktop.
paiza Online Hackathon
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 問題: https://paiza.jp/poh/kirishima | |
| 結果: http://paiza.jp/poh/kirishima/result/c7b9268a3c4b60e5c40aff903b3b9d96 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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