Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Created April 17, 2017 01:08
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 whatalnk/c1ca929e4fd019a337e533d6fcd4921e to your computer and use it in GitHub Desktop.
Save whatalnk/c1ca929e4fd019a337e533d6fcd4921e to your computer and use it in GitHub Desktop.
AtCoder ABC #017 [Ruby]
res = 0
while line = gets
e, s = line.chomp.split(" ").map(&:to_i)
res += e * s
end
puts res / 10
str = gets.chomp
res = str.gsub(/ch/, "").gsub(/o/, "").gsub(/k/, "").gsub(/u/, "")
if res == "" then
puts "YES"
else
puts "NO"
end
# TLE, 100
n, m = gets.chomp.split(" ").map(&:to_i)
ll = []
rr = []
ss = []
n.times do
l, r, s = gets.chomp.split(" ").map(&:to_i)
ll << l
rr << r
ss << s
end
ret = 0
m.times do |i|
score = 0
g = i + 1
n.times do |j|
if g >= ll[j] && g <= rr[j] then
next
else
score += ss[j]
end
end
ret = [ret, score].max
end
puts ret
# AC 101
n, m = gets.chomp.split(" ").map(&:to_i)
a = Array.new(m+2, 0)
sum = 0
n.times do
l, r, s = gets.chomp.split(" ").map(&:to_i)
a[l] += s
a[r+1] -= s
sum += s
end
(1..m).each do |i|
a[i+1] += a[i]
end
puts sum - a[1..m].min
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment