Instantly share code, notes, and snippets.

# whatalnk/abc061-a.rb Last active May 14, 2017

What would you like to do?
AtCoder ABC #061
 a, b, c = gets.chomp.split(" ").map(&:to_i) if c >= a && c <= b then puts "Yes" else puts "No" end
 n, m = gets.chomp.split(" ").map(&:to_i) h = Array.new(n+1, 0) m.times do a, b = gets.chomp.split(" ").map(&:to_i) h[a] +=1 h[b] +=1 end (1..(n)).each do |i| puts h[i] end
 n, k = gets.chomp.split(" ").map(&:to_i) h = Hash.new(0) n.times do a, b = gets.chomp.split(" ").map(&:to_i) h[a] += b end ret = 0 h.sort.each do |a, b| ret += b if ret >= k then puts a exit end end
 N, m = gets.chomp.split(" ").map(&:to_i) INF = 1 << 50 N_MAX = 1000 M_MAX = 2000 a = Array.new(N_MAX) b = Array.new(M_MAX) c = Array.new(M_MAX) m.times do |i| aa, bb, cc = gets.chomp.split(" ").map(&:to_i) a[i] = aa b[i] = bb c[i] = cc * -1 end dist = Array.new(N_MAX, INF) dist[0] = 0 (N - 1).times do |loop| m.times do |i| next if dist[a[i] - 1] == INF if dist[b[i] - 1] > dist[a[i] - 1] + c[i] then dist[b[i] - 1] = dist[a[i] - 1] + c[i] end end end ans = dist[N - 1] negative = Array.new(N_MAX, false) N.times do |loop| m.times do |i| next if dist[a[i] - 1] == INF if dist[b[i] - 1] > dist[a[i] - 1] + c[i] then dist[b[i] - 1] = dist[a[i] - 1] + c[i] negative[b[i] - 1] = true end if negative[a[i] - 1] then negative[b[i] - 1] = true end end end if negative[N - 1] puts "inf" else puts ans * -1 end
to join this conversation on GitHub. Already have an account? Sign in to comment