Skip to content

Instantly share code, notes, and snippets.

@nullkal
Created January 5, 2015 09:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nullkal/0b23ed80ebcb1319d83e to your computer and use it in GitHub Desktop.
Save nullkal/0b23ed80ebcb1319d83e to your computer and use it in GitHub Desktop.
paizaのアレをRubyのワンライナーで解いてみた
# 01
p $<.drop(1).map(&:to_i).inject(&:+)
# 02
p $<.drop(1).inject(0){|m,n|t,s,p=n.split.map(&:to_i);m+=p.*t>s ?t-s :0}
# 03
t,m,*p=gets.to_i,c=0;$<.each{|n|c+=l=n.to_i;p<<l;p.size<t||(m>c||m=c)&&c-=p.shift};p m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment