Cod sursa(job #2300755)

Utilizator driver71528@gmail.comTerec Andrei-Sorin [email protected] Data 11 decembrie 2018 22:36:52
Problema Subsir crescator maximal Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.19 kb
#include <iostream>
#include <fstream>
#include <set>
#include <vector>
using namespace std;

ifstream f("scmax.in");
ofstream g("scmax.out");
int n;

struct comp
{
    operator()(const vector<int> &a,const vector<int> &b)
    {
        return a.size()>b.size();
    }
};
typedef multiset<vector<int>,comp>::iterator it;
multiset<vector<int>,comp >s;

int main()
{
    f>>n;
    int z;
    it j;
    for(int i=1;i<=n;i++)
    {
        f>>z;
        vector<int> a;
        for(j=s.begin();j!=s.end() && j->back()>=z;j++);
        if(j==s.end())
            a.push_back(z);
        else
        {
            a=*j;
            a.push_back(z);
        }
        pair<it,it> k;
        for(k=s.equal_range(a);k.first!=k.second;)
        {
            it aux;
            if(k.first->back()>=z)
            {
                k.first++;
                aux=k.first;
                k.first--;
                s.erase(k.first);
                k.first=aux;
            }
        }
        s.insert(a);
    }
    vector<int> rez=*s.begin();
    g<<rez.size()<<'\n';
    for(int i=0;i<rez.size();i++)
        g<<rez[i]<<' ';
    f.close();
    g.close();
    return 0;
}