Last active
January 10, 2019 09:17
-
-
Save kou029w/4905fd94df5032b1ecda9f867b355c6c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Author
kou029w
commented
Oct 12, 2017
while str = STDIN.gets
end
これで標準入力が取得できるんだ...知らなかった
n, c = STDIN.gets.split(' ').map(&:to_i)
l=[]
while i = STDIN.gets
l << i.to_i
end
l.delete_if {|i| i > c }
sum = 0
l.each {|i| sum += (i == c || i + 1 == c ? 1 : 0) }.delete_if {|i| i == c || i + 1 == c }
l.sort!
while i = l.pop
sum+=1
l.each do|j|
if i + j + 1 <= c
l-=[j]
break
end
end
end
puts sum
1時間50分もかかった
間違えてた
n, c = STDIN.gets.split(' ').map(&:to_i)
l=[]
while i = STDIN.gets
l << i.to_i
end
sum = 0
l.each {|i| sum += (i == c || i + 1 == c ? 1 : 0) }.delete_if {|i| i == c || i + 1 == c }
l.sort!
while i = l.pop
sum+=1
l.each_with_index do |j,ix|
if i + j + 1 <= c
l.delete_at(ix)
break
end
end
end
puts sum
TLEだ
整理した
n, c = STDIN.gets.split(' ').map(&:to_i)
sum = 0
l = STDIN.read.split("\n").map(&:to_i).each {|i| sum += (i == c || i + 1 == c ? 1 : 0) }.delete_if {|i| i == c || i + 1 == c }.sort
while i = l.pop
sum+=1
l.each_with_index do |j,ix|
if i + j + 1 <= c
l.delete_at(ix)
break
end
end
end
puts sum
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment