Cod sursa(job #2474730)

Utilizator bmarcuBogdan Marcu bmarcu Data 15 octombrie 2019 19:23:19
Problema Subsecventa de suma maxima Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.01 kb
#include <iostream>
#include <fstream>

using namespace std;
ifstream fin ("scmax.in");
ofstream fout ("scmax.out");

int v[100000];

int main () {
  int n;
  fin >> n;
  for (int i = 1; i <= n; i++)
    fin >> v[i];


  int lmax = 0, l = 1;
  int bmax, emax;
  int ok = 1;
  int b, e;
  for (int i = 2; i <= n; i++) {
    if (v[i] >= v[i - 1]) {
      if (ok == 1) {
        if (v[i] != v[i - 1]) {
          b = i - 1;
          ok = 0;
          l++;
        }
      }
      else if (v[i] != v[i - 1])
        l++;
    }
    if (v[i] < v[i - 1] || i == n) {
      ok = 1;
      if (l > lmax && v[i] < v[i - 1]) {
        lmax = l;
        emax = i - 1;
        bmax = b;
      }
      else if (l > lmax && i == n)
      {
        lmax = l;
        emax = i;
        bmax = b;
      }
      //cout << l << ' ';
      l = 1;
    }
  }

  fout << lmax << endl;
  for (int i = bmax; i <= emax; i++)
    fout << v[i] << ' ';

  // fout << lmax << ' ' << bmax << ' ' << emax ;


}