Cod sursa(job #808593)

Utilizator icb_mnStf Cic icb_mn Data 6 noiembrie 2012 22:39:09
Problema Subsir crescator maximal Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1.12 kb
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

int n;
int main()
{
    freopen("scmax.in", "r", stdin);
    freopen("scmax.out", "w", stdout);

    scanf("%d", &n);

    vector<int> v;
    vector<int> best(n);
    vector<int> pozitii_el_max(n);
    for(int i = 1; i <= n; ++i)
    {
        int el;
        scanf("%d", &el);
        v.push_back(el);
    }
    best[n - 1] = 1;
    int maxim = 0;
    for(int i = n - 2; i >= 0; --i)
    {
        maxim = 0;
        for(int j = i + 1; j < n; ++j)
        {
            if(v[j] > v[i] && best[j] > maxim)
            {
                maxim = best[j];
                pozitii_el_max[i] = j;
            }
            best[i] = maxim + 1;
        }
    }
    maxim = 0;
    int poz_max = 0;
    for(int i = 0; i < n; ++i)
        if(best[i] > maxim)
            maxim = best[i], poz_max = i;
    printf("%d\n", maxim);
    printf("%d ", v[poz_max]);
    for(int i = poz_max + 1; i < n; ++i)
    {
        if(v[i] > v[poz_max] && best[i] == maxim - 1)
            printf("%d ", v[i]),maxim--;

    }

    return 0;
}