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 (Clang 3.8.0) (judge verdict: Time Limit Exceeded)


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

#define YYDBG 0

#if YYDBG==1
#define PRINTF(...) printf(__VA_ARGS__);
#define FOR for
#define IF if
#define ELSE else
#else
#define PRINTF(...) 
#define FOR(...)
#define IF(...)
#define ELSE 
#endif


int inputs[100000];
int colors[100000];
int N;
int main(void) {
    int i,j,k;
    int count;

    scanf("%d\n", &N);
    for(i=0;i<N;i++) { 
        scanf("%d\n", &(inputs[i]));
    }
    memset(colors, 0, sizeof(colors));

    PRINTF("in : ");
    FOR(i=0;i<N;i++) {
        PRINTF("%2d ", inputs[i]);
    }
    PRINTF("\n");

    count = 0;
    for(i=N-1;i>=0;i--) {
        int v = inputs[i];
        for(j=i+1;j<N;j++) {
            if (v < inputs[j]) {
                for(k=j;k>=i;k--) {

                    PRINTF("(%d,%d,%d):(%d,%d)[%d,%d] ", i, j, k, v, inputs[j], colors[j], colors[k]);
                    if ((v >= inputs[k]) && (colors[j] == colors[k])) {
                        break;
                    }
                }
                PRINTF("\n");
                if (k < i) {
                    colors[i] = colors[j];
                    break;
                }
            }
        }

        if(colors[i] == 0) {
            count++;
            colors[i] = count;
        }
    }

    PRINTF("out: ");
    FOR(i=0;i<N;i++) {
        PRINTF("%2d ", colors[i]);
    }
    PRINTF("\n");

#if 0
    count = 1;
    for(i=1;i<N;i++) {
        if(inputs[i-1] >= inputs[i]) {
            count++;
        }
    }

    count = 1;
    int current = inputs[0];
    for(i=1;i<N;i++) {
        if ( current >= inputs[i] ) {continue;}
        else {
            check();
        }
    }
#endif



    printf("%d\n", count);
    return 0;
}


int check(int current, int start, int index) {
    int i;
    for(i=index+1;i<N;i++) {
        if ( current >= inputs[i] ) {continue;}
        else {
            check(inputs[i], start, i);
        }
    }
}