Cod sursa(job #1356815)

Utilizator HunMakerFazekas Hunor HunMaker Data 23 februarie 2015 16:45:19
Problema Subsir crescator maximal Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.8 kb
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    int n,i,j,max=1;
    ifstream file1;
    file1.open("scmax.in");
    file1 >> n;
    int V[100000],W[100000];
    for( i=0 ; i<n ; i++ )
    {
     file1 >> V[i];
     W[i]=1;
    }
    file1.close();
    for( i=(n-1) ; i>=0 ; i-- )
    {
     for( j=(n-1) ; j>i ; j-- )
     {
      if( V[i]<V[j] && W[j]==W[i])
      {
       W[i]++;
      }
     }
    }
    for( i=0 ; i<n ; i++ )
    {
     if(max<W[i])
       {
        max=W[i];
        j=i;
       }
    }
    ofstream file2;
    file2.open("scmax.out");
    file2 << max << '\n';
    for( i=j ; i<n ; i++ )
    {
     if(W[i]==max)
     {
      file2 << V[i] << " ";
      max--;
     }
    }
    file2.close();

    return 0;
}