Cod sursa(job #1232164)

Utilizator thinkphpAdrian Statescu thinkphp Data 22 septembrie 2014 11:48:15
Problema Subsecventa de suma maxima Scor 40
Compilator c Status done
Runda Arhiva educationala Marime 0.78 kb
#include <stdio.h>
#define FIN "ssm.in"
#define FOUT "ssm.out"
#define MAXN 100001

int N, arr[ MAXN ];

void read() {

     int i;

     freopen(FIN, "r", stdin);

     scanf("%d", &N);

     for(i = 1; i <= N; i++) {

         scanf("%d", &arr[ i ]);
     } 

     fclose( stdin );
};

void solve() {

     int i,  

         begin, start,

         end, bestSum = -0x3f3f3f3f, sum = 0; 

     freopen(FOUT, "w", stdout);

     for(i = 1; i <= N; i++) {

         sum += arr[ i ];

         if( sum < 0 ) sum = 0, start = i + 1;
 
         if( sum > bestSum ) bestSum = sum, begin = start, end = i;
     }
 
     printf("%d %d %d", bestSum, begin, end);

     fclose( stdout );
};

int main() {

    read();
    solve();
 
    return(0);
};