Cod sursa(job #872616)

Utilizator petiVass Peter peti Data 6 februarie 2013 13:51:12
Problema Subsecventa de suma maxima Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.86 kb
#include <iostream>
#include <fstream>
#include <limits>

using namespace std;

int main()
{
    ifstream ifs("ssm.in");
    ofstream ofs("ssm.out");

    int N;
    ifs>>N;
    int *m=new int[N];

    for(int i=0;i<N;i++)
        ifs>>m[i];


    long long int maxsum=0,minsum=numeric_limits<long long>::max();
    int l=0,r=0;


    for(int i=0;i<N;i++){
        for(int j=0;j<N ;j++){
            long long int s=0;
            for(int idx=i;idx<=j;idx++){
                s+=m[idx];
            }
            if(s>maxsum){
                maxsum=s;
                r=j;
            }
            if(s<minsum){
                minsum=s;
                l=j+1;
            }
        }
    }


//    cout<<"l "<<l<<"\n";
//    cout<<"r "<<r<<"\n";
    ofs<<maxsum<<" "<<l+1<<" "<<r+1;
    return 0;
}
//     -1 2 3 2 -5 -5 6 7 -5