Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Control.Monad
- import qualified Data.ByteString.Char8 as B
- import Data.Maybe
- import Data.List
- import Control.Arrow
- readInt :: B.ByteString -> Int
- readInt = fst . fromJust . B.readInt
- main :: IO ()
- main = do
- [lng] <- liftM (map readInt . B.words) B.getLine
- lst <- liftM (map readInt . take lng . B.words) B.getLine :: IO [Int]
- [n] <- liftM (map readInt . B.words) B.getLine
- putStrLn "Input: "
- print lst
- print n
- putStrLn "Result: "
- let res = solve lst n
- print res
- comp (a1,b1) (a2,b2) | b1 < b2 = LT
- | otherwise = GT
- finalize [] = []
- finalize (h:t) = [(fst h)] ++ (finalize t)
- solve lst n = finalize good
- where good = sortBy comp (take n (reverse (sort (zip lst [0..]))))
- -- 7
- -- 1 5 3 7 6 2 9
- -- 4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement