Created
February 28, 2018 12:53
-
-
Save maehrm/4df4aa3d2a55e537e589b9e6dd9758d8 to your computer and use it in GitHub Desktop.
Longest Increasing Subsequence | Aizu Online Judge http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_D
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
dp, a = [], [] | |
n = gets.to_i | |
n.times { | |
a << gets.to_i | |
dp << 1e9+1 | |
} | |
a.each_index{|i| | |
dp[dp.bsearch_index {|x| x >= a[i]}] = a[i] | |
} | |
ans = dp.bsearch_index {|x| x >= 1e9+1 } | |
puts ans.nil? ? dp.size : ans |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment