Cod sursa(job #935140)

Utilizator whoasdas dasdas who Data 1 aprilie 2013 20:31:03
Problema Subsir crescator maximal Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.98 kb
/*
ID: i.adri1
PROG: scmax
LANG: C++
*/

#include <iostream>
#include <fstream>
#include <assert.h>
#include <math.h>
#include <string.h>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
using namespace std;

#define NMAX 100001
#define inf 0x7fffffff

int main()
{
    ifstream in("scmax.in");
    ofstream out("scmax.out");
    int n, lmax = 0, x, i, j;
    in>>n;
    int v[n];
    map<int, int> *m = new map<int, int>[n];

    for (j = 0; j < n; j++) {
        in>>x;
        for(i = 0; i < lmax && x > v[i]; i++);
        v[i] = x; m[i][x] = (i > 0 ? v[i-1] : 0);
        if (i >= lmax) {
            lmax = i + 1;
        }

    }
    out<<lmax<<endl;

    int sol[n];
    int el = v[lmax-1];
    for (i = lmax - 1; i >= 0; i--) {
        sol[i] = el;
        el = m[i][el];
    }
    for (i = 0; i < lmax; i++)
        out<<sol[i]<<" ";
    return 0;
}