Skip to content

Instantly share code, notes, and snippets.

@parrot-studio

parrot-studio/enkoi

Last active Aug 29, 2015
Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@parrot-studio parrot-studio commented Dec 3, 2014

@parrot-studio

This comment has been minimized.

Copy link
Owner Author

@parrot-studio parrot-studio commented Dec 3, 2014

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

@parrot-studio

This comment has been minimized.

Copy link
Owner Author

@parrot-studio parrot-studio commented Dec 3, 2014

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