Created
December 4, 2014 21:22
-
-
Save mayth/9ebc0a17ee715d9741ea to your computer and use it in GitHub Desktop.
paiza Online Hackathon 4 Lite : Answers with F#
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
// https://paiza.jp/poh/enkoi-second/e144f4da | |
open System | |
let readLines (reader : IO.TextReader) = | |
seq { | |
let eof = ref false | |
while not !eof do | |
match reader.ReadLine() with | |
| null -> eof := true | |
| str -> yield str | |
} | |
[<EntryPoint>] | |
let main args = | |
let result = readLines Console.In | |
|> Seq.skip 1 | |
|> Seq.map int | |
|> Seq.sum | |
Console.WriteLine(result) | |
0 |
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
// https://paiza.jp/poh/enkoi-third/357303dc | |
open System | |
let readLines (reader : IO.TextReader) = | |
seq { | |
let eof = ref false | |
while not !eof do | |
match reader.ReadLine() with | |
| null -> eof := true | |
| str -> yield str | |
} | |
[<EntryPoint>] | |
let main args = | |
let result = readLines Console.In | |
|> Seq.skip 1 | |
|> Seq.map (fun s -> s.Trim().Split([|' '|]) |> (Array.map int)) | |
|> Seq.sumBy (fun item -> max 0 ((item.[0] - item.[1]) * item.[2])) | |
printfn "%d" result | |
0 |
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
// https://paiza.jp/poh/enkoi-ending/6dfbbfb3 | |
open System | |
let readLines (reader : IO.TextReader) = | |
seq { | |
let eof = ref false | |
while not !eof do | |
match reader.ReadLine() with | |
| null -> eof := true | |
| str -> yield str | |
} | |
[<EntryPoint>] | |
let main args = | |
let tmp = Console.ReadLine().Split([|' '|]) | |
let t = int tmp.[0] | |
let n = int tmp.[1] | |
let sum = readLines Console.In | |
|> Seq.map int | |
|> Seq.scan (fun acc elem -> acc + elem) 0 | |
|> Seq.toArray | |
let result = seq { 1 .. (n - t + 1) } | |
|> Seq.map (fun i -> sum.[i + t - 1] - sum.[i - 1]) | |
|> Seq.max | |
printfn "%d" result | |
0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment