Cod sursa(job #3335505)

Utilizator calinulCalin Cernat calinul Data 22 ianuarie 2026 19:52:13
Problema Subsecventa de suma maxima Scor 100
Compilator c-64 Status done
Runda Arhiva educationala Marime 0.77 kb
#include <stdio.h>
#include <ctype.h>

FILE *fin, *fout;

int rInt() {
  int rez = 0, ch, p = 1;
  while ( isspace( ch = fgetc( fin ) ) );
  if ( ch == '-' ) {
    p = -1;
    ch = fgetc( fin );
  }
  do
    rez = rez * 10 + ch - '0';
  while ( isdigit( ch = fgetc( fin ) ) );
  return rez * p;
}

int main() {
  long long s, smax;
  int n, i, p = 1, st = 1, dr = 1;

  fin = fopen( "ssm.in", "r" );
  n = rInt();
  s = smax = rInt();
  for ( i = 2; i <= n; i++ ) {
    s += rInt();
    if ( s > smax ) {
      smax = s;
      st = p;
      dr = i;
    }
    if ( s < 0 ) {
      s = 0;
      p = i + 1;
    }
  }
  fclose( fin );

  fout = fopen( "ssm.out", "w" );
  fprintf( fout, "%lld %d %d\n", smax, st, dr );
  fclose( fout );

  return 0;
}