Cod sursa(job #2404032)

Utilizator popashtefan10Popa Stefan popashtefan10 Data 12 aprilie 2019 11:13:02
Problema Subsecventa de suma maxima Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.54 kb
#include <iostream>
#include <cstdio>

using namespace std;

int main() {
  FILE *fin = fopen("ssm.in", "r");
  FILE *fout = fopen("ssm.out", "w");
  long long n, i, x, maxim = -1e9, s = 0, st, stmax, drmax;

  fscanf(fin, "%lld", &n);
  for(i = 1; i <= n; i++) {
    fscanf(fin, "%lld", &x);
    if(x > x + s) {
      s = x;
      st = i;
    }
    else
      s += x;
    if(s > maxim) {
      maxim = s;
      stmax = st;
      drmax = i;
    }
  }
  fprintf(fout, "%lld %lld %lld", maxim, stmax, drmax);

  return 0;
}