abc170a.rb
xi = gets.chomp.split(" ").map!{|item| item.to_i}
for i in 1..5 do
if xi[i-1] == 0
print(i )
end
end
abc170.rb
xi = gets.chomp.split(" ").map!{|item| item.to_i}
for f in 0..xi[0]
if xi[1] == (f*2) + (xi[0]-f)*4
puts "Yes"
exit
end
end
puts "No"
Forgetting when one is 0, I turned the loop from 1 and once wa
abc170.rb
x,n = gets.chomp.split(" ").map!{|item| item.to_i}
p = gets.chomp.split(" ").map!{|item| item.to_i}
p.sort!
if n == 0
puts x
exit
end
y = p.max+1
for i in 0..p.max+1 do
if y > (x-i).abs
if p.include?(i)
else
y = (x-i).abs
a = i
end
end
end
puts a
If the initial value of y is turned without the maximum value of p + 1, wa is not noticed at 1 1 1 and cannot be solved in time. Is the difference increased by 1 from 0 and included in the array rather than implementing it as written? It's simpler as a code to check.
Recommended Posts