Problem:
Score : 500 points

Problem Statement

You are given a sequence with N integers: A = \{ A_1, A_2, \cdots, A_N \}.
For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:

If A_i and A_j (i < j) are painted with the same color, A_i < A_j.

Find the minimum number of colors required to satisfy the condition.

Constraints

1 \leq N \leq 10^5

0 \leq A_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
A_1
:
A_N

Output

Print the minimum number of colors required to satisfy the condition.

Sample Input 1

5
2
1
4
5
3

Sample Output 1

2

We can satisfy the condition with two colors by, for example, painting 2 and 3 red and painting 1, 4, and 5 blue.

Sample Input 2

4
0
0
0
0

Sample Output 2

4

We have to paint all the integers with distinct colors.

Solution in C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System; 
using System.Text;
using System.Collections.Generic;
using System.Collections;
using System.Linq; 
using E = System.Linq.Enumerable; 


class Program {
   static long mod = 1000000007;
   static long end = 100000;
   static long st =  100000;
   
    static void Main(string[] args) {
        var N = long.Parse(Console.ReadLine());
        var A = new long[1000000];
        //var A = new List<long>();
        A[st] = long.Parse(Console.ReadLine());
        for(int i = 1;i < N;i++){
            var num = long.Parse(Console.ReadLine());
            
            var ins = UpperBound(A,num);
            //Console.WriteLine(ins);　
            if(A[st] >= num){
                st--;
                A[st] = num;
            }else{
                //Console.WriteLine("ins:"+ins+"num:"+num);
                if(A[ins-1] < num){
                   A[ins-1] = num;
                  Console.WriteLine(A[ins-1]);
                }else{
                  ins = UpperBound(A,num-1);
                  A[ins-1] = num;
                //  Console.WriteLine(i);
                }
                
            }
            //A.Insert(ins,num);
        }
        
        Console.WriteLine(end-st+1);
        
     }
     
     
     public static long UpperBound<T>(T[] a, T v) { return UpperBound(a, v, Comparer<T>.Default);
     }
     
     public static long UpperBound<T>(T[] a, T v, Comparer<T> cmp) {
         var l = st;
         var r = end;
         while (l <= r) { var mid = l + (r - l) / 2; var res = cmp.Compare(a[mid], v); if (res <= 0) l = mid + 1; else r = mid - 1; } 
         return l;
      }
     
     
     public static long RepPow(long x, long p, long m = 1000000007){ 
     if (p == 0) return 1;
     if (p == 1) return x % m; long b = RepPow(x, p / 2, m) % m; if (p % 2 == 0) { return (b * b) % m; } else { return (x * ((b * b) % m)) % m; }}
}
     
class UnionFind

 

{

 

// 親要素のインデックスを保持する

 

// 親要素が存在しない(自身がルートである)とき、マイナスでグループの要素数を持つ

 

public long[] Parents { get; set; }

 

public UnionFind(long n)

 

{

 

this.Parents = new long[n];

 

for (int i = 0; i < n; i++)

 

{

 

// 初期状態ではそれぞれが別のグループ(ルートは自分自身)

 

// ルートなのでマイナスで要素数(1個)を保持する

 

this.Parents[i] = -1;

 

}

 

}

 

 

 

// 要素xのルート要素はどれか

 

public long Find(long x)

 

{

 

// 親がマイナスの場合は自分自身がルート

 

if (this.Parents[x] < 0) return x;

 

// ルートが見つかるまで再帰的に探す

 

// 見つかったルートにつなぎかえる

 

this.Parents[x] = Find(this.Parents[x]);

 

return this.Parents[x];

 

}

 

 

 

// 要素xの属するグループの要素数を取得する

 

public long Size(long x)

 

{

 

// ルート要素を取得して、サイズを取得して返す

 

return -this.Parents[this.Find(x)];

 

}

 

 

 

// 要素x, yが同じグループかどうか判定する

 

public bool Same(long x, long y)

 

{

 

return this.Find(x) == this.Find(y);

 

}

 

 

 

// 要素x, yが属するグループを同じグループにまとめる

 

public bool Union(long x, long y)

 

{

 

// x, y のルート

 

x = this.Find(x);

 

y = this.Find(y);

 

// すでに同じグループの場合処理しない

 

if (x == y) return false;

 

 

 

// 要素数が少ないグループを多いほうに書き換えたい

 

if (this.Size(x) < this.Size(y))

 

{

 

var tmp = x;

 

x = y;

 

y = tmp;

 

}

 

// まとめる先のグループの要素数を更新

 

this.Parents[x] += this.Parents[y];

 

// まとめられるグループのルートの親を書き換え

 

this.Parents[y] = x;

 

return true;

 

}

 

}





     
                   
public class PriorityQueue<T> : IEnumerable<T> { private readonly List<T> _data = new List<T>(); private readonly IComparer<T> _comparer; private readonly bool _isDescending; public PriorityQueue(IComparer<T> comparer, bool isDescending = true) { _comparer = comparer; _isDescending = isDescending; } public PriorityQueue(Comparison<T> comparison, bool isDescending = true) : this(Comparer<T>.Create(comparison), isDescending) { } public PriorityQueue(bool isDescending = true) : this(Comparer<T>.Default, isDescending) { } public void Enqueue(T item) { _data.Add(item); var childIndex = _data.Count - 1; while (childIndex > 0) { var parentIndex = (childIndex - 1) / 2; if (Compare(_data[childIndex], _data[parentIndex]) >= 0) break; Swap(childIndex, parentIndex); childIndex = parentIndex; } } public T Dequeue() { var lastIndex = _data.Count - 1; var firstItem = _data[0]; _data[0] = _data[lastIndex]; _data.RemoveAt(lastIndex--); var parentIndex = 0; while (true) { var childIndex = parentIndex * 2 + 1; if (childIndex > lastIndex) break; var rightChild = childIndex + 1; if (rightChild <= lastIndex && Compare(_data[rightChild], _data[childIndex]) < 0) childIndex = rightChild; if (Compare(_data[parentIndex], _data[childIndex]) <= 0) break; Swap(parentIndex, childIndex); parentIndex = childIndex; } return firstItem; } public T Peek() { return _data[0]; } private void Swap(int a, int b) { var tmp = _data[a]; _data[a] = _data[b]; _data[b] = tmp; } private int Compare(T a, T b) { return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b); } public int Count => _data.Count; public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); }