Cod sursa(job #2640881)

Utilizator Ionut2791Voicila Ionut Marius Ionut2791 Data 8 august 2020 20:58:08
Problema Subsecventa de suma maxima Scor 80
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.03 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

const int nMax = 6000005;

long long spActual, nr, minSecv, maxSecv;
int n, pozMinSecv, pozMaxSecv;

int main(){
    //ifstream fin("date.in");
    ifstream fin("ssm.in");
    ofstream fout("ssm.out");

    fin >> n;



    fin >> spActual;
    minSecv = spActual;
    maxSecv = spActual;
    pozMaxSecv = 1;
    pozMinSecv = 1;

    for(int i = 2; i <= n; ++i){
        fin >> nr;
        spActual += nr;

        if(minSecv > spActual){
            minSecv = spActual;
            pozMinSecv = i;
        }
        if(maxSecv < spActual){
            maxSecv = spActual;
            pozMaxSecv = i;
        }
       // cout << minSecv << " " << maxSecv << " " << spActual << "\n";
    }
   // cout << pozMinSecv << "\n";
    if(pozMinSecv == 1)
        fout << maxSecv << " " << 1 << " " << n;
    else
        fout << maxSecv - minSecv << " " << pozMinSecv + 1<< " " << pozMaxSecv<< "\n";

    return 0;
}