Cod sursa(job #1866240)

Utilizator herbertoHerbert Mohanu herberto Data 2 februarie 2017 19:37:15
Problema Subsecventa de suma maxima Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.52 kb
#include<stdio.h>
using namespace std;
#define INF 9223372036854775808

int main(){
  FILE*fin=fopen("ssm.in", "r");
  FILE*fout=fopen("ssm.out", "w");
  int n, i, begin, end, b;
  long long s, a, max, smax;
  fscanf(fin, "%d", &n);
  s=0;
  smax=-INF;
  begin=1;
  b=1;
  for(i=1; i<=n; i++){
    fscanf(fin, "%lld", &a);
    if(s<0){
      s=0;
      b=i;
    }
    s+=a;
    if(s>smax){
      smax=s;
      begin=b;
      end=i;
    }
  }
  fprintf(fout, "%lld %d %d", smax, begin, end);
  return 0;
}