Longest double increasing subsequence (LIS variant)
A counter example where your algorithm fails: 
S = 0 7 1 4 6 5 3 2.

Expected : 5, your algorithm would produce 3

There is an O(n^3) dynamic programming based algorithm for this if you are interested :)