Last active
March 19, 2020 09:43
-
-
Save louy2/832006947d5fb4ea6fb267021faa9573 to your computer and use it in GitHub Desktop.
Rust solution to Paiza Online Hackathon Lite 4 ending
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/enkoi-ending/ed57428d | |
-- しゃくとり法 | |
import Data.List | |
main = do | |
t:_ <- map read . words <$> getLine | |
interact $ show . solve t . map read . lines | |
solve :: Int -> [Int] -> Int | |
solve t xs = maximum $ solve' t xs | |
solve' :: Int -> [Int] -> [Int] | |
solve' t xs = scanl' go (sum (take t xs)) (zip xs (drop t xs)) | |
where | |
go s (l, h) = s - l + h |
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/enkoi-ending/8e85234f | |
// 累積和 | |
use std::io::BufRead; | |
fn main() { | |
let stdin = std::io::stdin(); | |
let mut l = stdin.lock().lines().map(Result::unwrap); | |
let t: usize = { | |
let first_line = l.next().unwrap(); | |
let mut tmp = first_line.split(" ").map(|x| x.parse().unwrap()); | |
tmp.next().unwrap() | |
}; | |
let m: Vec<i64> = l.map(|x| x.parse().unwrap()).collect(); | |
let accum: Vec<i64> = [0].iter().chain(m.iter()).scan(0, |sum, &x| { *sum += x; Some(*sum) }).collect(); | |
let result: i64 = accum.windows(t + 1).map(|w| w[t] - w[0]).max().unwrap(); | |
println!("{}", result); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment