結果
問題 | No.198 キャンディー・ボックス2 |
ユーザー |
|
提出日時 | 2018-06-23 16:06:47 |
言語 | Haskell (9.10.1) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 446 bytes |
コンパイル時間 | 11,964 ms |
コンパイル使用メモリ | 171,264 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-16 10:20:09 |
合計ジャッジ時間 | 12,941 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 26 |
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default [1 of 2] Compiling Main ( Main.hs, Main.o ) [2 of 2] Linking a.out
ソースコード
import Control.Applicative ((<$>)) import Control.Monad (replicateM) import Data.List (sort, foldl') main :: IO () main = do b <- readLn n <- readLn solve b n <$> replicateM n (read <$> getLine) >>= print solve :: Int -> Int -> [Int] -> Int solve b n cs = foldl' (\x y -> x + (abs (y - (if h < 0 then m' else m)))) 0 cs where scs = sort cs m = scs !! (n `div` 2) m' = (b + sum cs) `div` n h = b + sum cs - n * m