http://acm.hdu.edu.cn/showproblem.php?pid=1257
/*
2011-9-13
author:BearFly1990
*/
package acm.hdu.tests;
import java.io.BufferedInputStream;
import java.util.Scanner;
public class HDU_1257 {
private static int[] height = new int[100000];
private static int hindex = 0;
private static int[] arr = new int[100000];
public static void main(String[] args) {
Scanner in = new Scanner(new BufferedInputStream(System.in));
while(in.hasNext()){
int n = in.nextInt();
arr[0] = in.nextInt();
height[0] = arr[0];
hindex = 0;
int j = 1;
for(int i = 1; i < n; i++){
arr[i] = in.nextInt();
if(arr[i] >= height[hindex]){
height[j++] = arr[i];
if(height[j-1] > height[hindex]){
hindex = j-1;
}
}else {
int k,min = Integer.MAX_VALUE,min_index =0;
for(k = 0; k < j; k++){
if(height[k] >= arr[i] && min > height[k] - arr[i]){
min = height[k] - arr[i];
min_index = k;
}
}
height[min_index] = arr[i];
}
}
System.out.println(j);
}
}
}