Cod sursa(job #2458441)

Utilizator Codrut112Codrut Copas Codrut112 Data 20 septembrie 2019 16:35:19
Problema Subsir crescator maximal Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.94 kb
#include <iostream>
#include <fstream>
using namespace std;
int n,i,j,mx,mx1,w[100001],t,l;
unsigned long long int v[100001];
int main()
{
    ifstream f("scmax.in");
    ofstream g("scmax.out");
    f>>n;
    for(i=1; i<=n; i++) f>>v[i];
    for(i=1; i<=n; i++) w[i]++;
    for(i=0; i<=n; i++)
    {
        if(w[i]==1)
        {
            for(j=i+1; j<=n; j++)
            {
                if(v[i]<v[j]  and w[j]==1)
                {
                    w[i]++;
                    w[j]=0;
                    for(t=j+1; t<=n; t++)if(v[j]==v[t])
                        {
                            for(l=t; l<=n; l++)v[l]=v[l+1];
                            n--;
                        }
                }
            }
        }
    }
    for(i=1; i<=n; i++)if(w[i]>mx)
        {
            mx=w[i];
            mx1=i;
        }
    g<<mx;g<<endl<<v[mx1]<<" ";
for(i=mx1;i<=n;i++)if(v[mx1]<v[i]) g<<v[i]<<" ";

}