diff options
-rwxr-xr-x | 1 | 49 |
1 files changed, 49 insertions, 0 deletions
@@ -0,0 +1,49 @@ +#!/bin/sh -eu +p1() ( + max=0 + temp=0 + while IFS= read -r l + do + if [ -z $l ] + then + if [ $temp -gt $max ] + then + max=$temp + fi + temp=0 + else + temp=$((temp + l)) + fi + done < input.txt + printf "%s\n" "$max" +) + +p2() ( + set -- 0 0 0 + temp=0 + while IFS= read -r l + do + # TODO: check EOF + if [ -z $l ] + then + if [ $temp -gt $1 ] + then + shift + set -- $@ $temp + set -- $(printf "%s\n" "$@" | sort -n) + fi + temp=0 + else + temp=$((temp + l)) + fi + done < input.txt + sum=0 + for i in $@ + do + sum=$((sum + i)) + done + printf "%s\n" "$sum" +) + +p1 +p2 |