LoginSignup
1
0

More than 3 years have passed since last update.

蟻本の区間スケジューリング問題をrubyで解いてみる(記録用)

Posted at

問題

image.png

入力例

5
1 2 4 6 8
3 5 7 9 10

回答例

count=gets.to_i
starts=gets.chomp.split(" ").map(&:to_i)
ends=gets.chomp.split(" ").map(&:to_i)
se=[]
kijun=0
answer=0
starts.map.with_index{|item,index|
  se[index]=[item,ends[index]]
}
se.sort_by! { |_, b| b }
se.map {|item|
  if kijun<item[0] then
    kijun=item[1]
    answer=answer+1
  end    
}
puts answer


1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0