Cod sursa(job #1356734)

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

using namespace std;

int main()
{
    int n,i,j,x,max;

    ifstream file1;
    file1.open("scmax.in");
    file1 >> n;
    int V[n],W[n];

    for( i=0 ; i<n ; i++ )
    {
     file1 >> x;
     V[i]=x;
     W[i]=1;
    }
    file1.close();
    max=W[0];
    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]++;
       if(max<W[i])
       {
        max=W[i];
        x=i;
       }
      }
     }
    }
    ofstream file2;
    file2.open("scmax.out");
    file2 << max << '\n';
    for( i=x ; i<n ; i++ )
    {
     if(W[i]==max)
     {
      file2 << V[i] << " ";
      max--;
     }
    }
    file2.close();

    return 0;
}