Created
July 10, 2013 13:16
-
-
Save LeastFixedPoint/5966192 to your computer and use it in GitHub Desktop.
This file contains 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.Monad (foldM) | |
split s = let prefix = takeWhile (/= ' ') s in (prefix, drop (1 + length prefix) s) | |
main = do | |
nm <- getLine | |
let (sn, sm) = split nm | |
let (n, m) = (read sn, read sm) | |
let step songs index = do | |
line <- getLine | |
let (frequency, name) = split line | |
let quality = read frequency * index | |
let song = (quality, name) | |
let (better, worse) = span ((>= quality) . fst) songs | |
return $ take m $ better ++ [song] ++ worse | |
songs <- foldM step [] [1..n] | |
sequence_ $ fmap (putStrLn . snd) songs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment