Skip to content

Instantly share code, notes, and snippets.

@parrot-studio
Last active August 29, 2015 14:10
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 parrot-studio/eb55972db9ff3852f9d7 to your computer and use it in GitHub Desktop.
Save parrot-studio/eb55972db9ff3852f9d7 to your computer and use it in GitHub Desktop.
https://paiza.jp/poh/enkoi
Ruby / CoffeeScript
process.stdin.resume()
process.stdin.setEncoding 'utf-8'
process.stdin.on 'data', (chunk) ->
lines = chunk.toString().split('\n')
size = parseInt lines.shift()
all = 0
for n in lines[0..(size-1)]
all += parseInt n
console.log all
size = gets.to_i
all = 0
size.times do
all += gets.to_i
end
puts all
process.stdin.resume()
process.stdin.setEncoding 'utf-8'
process.stdin.on 'data', (chunk) ->
lines = chunk.toString().split('\n')
size = parseInt lines.shift()
all = 0
for l in lines[0..(size-1)]
ds = l.toString().split(' ')
need = (parseInt ds[0]) - (parseInt ds[1])
continue if need <= 0
all += (parseInt ds[2]) * need
console.log all
size = gets.to_i
all = 0
size.times do
ds = gets.split(' ').map(&:to_i)
need = ds[0] - ds[1]
next if need <= 0
all += ds[2] * need
end
puts all
# テストは通るのにTaseCase4でエラー
process.stdin.resume()
process.stdin.setEncoding 'utf-8'
process.stdin.on 'data', (chunk) ->
lines = chunk.toString().split('\n')
ps = lines.shift().toString().split(' ')
size = parseInt ps[0]
len = parseInt ps[1]
now = 0
buf = []
for l in lines[0..(size-1)]
num = parseInt l
now += num
buf.push num
max = now
for l in lines[size..len-1]
num = parseInt l
now += (num - buf.shift())
max = now if now > max
buf.push num
console.log max
size, len = gets.split(' ').map(&:to_i)
now = 0
buf = []
size.times do
num = gets.to_i
now += num
buf << num
end
max = now
(len-size).times do
num = gets.to_i
now += (num - buf.shift)
max = now if now > max
buf << num
end
puts max
@parrot-studio
Copy link
Author

@parrot-studio
Copy link
Author

rev:eb5597 => https://paiza.jp/poh/enkoi-ending/290aaac9
TestCase7 : 0.43s => OK

@parrot-studio
Copy link
Author

rev:3b0955 => https://paiza.jp/poh/enkoi-ending/9e0466d1
いらない変数を削ったけど、誤差の範囲

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment