Last active
May 14, 2017 07:46
-
-
Save whatalnk/8f5e839fc0b49697e7e7d5d2a8de31aa to your computer and use it in GitHub Desktop.
AtCoder ABC #061
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a, b, c = gets.chomp.split(" ").map(&:to_i) | |
if c >= a && c <= b then | |
puts "Yes" | |
else | |
puts "No" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment