Cod sursa(job #2239384)

Utilizator DandeacDan Deac Dandeac Data 10 septembrie 2018 17:46:44
Problema Subsecventa de suma maxima Scor 5
Compilator cpp Status done
Runda Arhiva educationala Marime 0.73 kb
#include <iostream>
#include <fstream>
#include <climits>
using namespace std;
ifstream f ("ssm.in");
ofstream g ("ssm.out");
struct best
{
    int val;
    int minim;
}b[6000006];
int n,v[6000006];
int sp[6000006];
int minim = INT_MAX;
int maxim =  INT_MIN;
int maxpoz=1;

int main()
{

    f>>n;
    for(int i=1;i<=n;i++)
        f>>v[i];

    for(int i=1;i<=n;i++)
    {
        sp[i] = sp[i-1] + v[i];
        if(sp[i-1]<minim){
            minim = sp[i-1];
            b[i].minim = i;
        }

        b[i].val = sp[i] - minim;
        if(b[i].val > maxim){
            maxim = b[i].val ;
            maxpoz = i;
        }
    }

    g<<maxim<<' '<<b[maxpoz].minim<<' '<<maxpoz;

    return 0;
}