Cod sursa(job #1106814)

Utilizator alexandru213Bracau Alexandru alexandru213 Data 13 februarie 2014 11:04:23
Problema Subsecventa de suma maxima Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.53 kb
#include <fstream>
#include <limits.h>
using namespace std;
ifstream in("ssm.in");
ofstream out("ssm.out");
int s,n,x,smax,incmax,sfmax,sf,inc;
int main()
{
    smax=INT_MIN;
    s=0;
    in>>n;
    inc=sf=1;
    for(int i=1;i<=n;i++){
        in>>x;
        if(s+x>=x){
            s+=x;
            sf=i;}
        else{
            inc=sf=i;
            s=x;}
        if(s>smax){
            smax=s;
            incmax=inc;
            sfmax=sf;}
            }
    out<<smax<<" "<<incmax<<" "<<sfmax;
    return 0;
}