Cod sursa(job #3247973)

Utilizator S80P_ShadeslayerBadarau Andrei S80P_Shadeslayer Data 10 octombrie 2024 10:41:14
Problema Subsecventa de suma maxima Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.58 kb
#include <bits/stdc++.h>

using namespace std;

const int mx = 6e6 + 7;

ifstream fin ("ssm.in");
ofstream fout ("ssm.out");

int main()
{
    int n;
    fin >> n;
    int s = -1, smax = -mx;
    int st = 1, dr = 0, stmax = 0;
    int x;
    for(int i = 1; i <= n; i++)
    {
        fin >> x;
        if(s < 0)
        {
            s = 0;
            st = i;
        }
        s += x;
        if(s > smax)
        {
            smax = s;
            dr = i;
            stmax = st;
        }
    }
    fout << s  << ' ' << stmax  << ' ' << dr;
    return 0;
}