Cod sursa(job #3237996)

Utilizator winemomComan Erin winemom Data 14 iulie 2024 23:17:22
Problema Subsecventa de suma maxima Scor 95
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.49 kb
#include <bits/stdc++.h>
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");

int n;
long long x, smax, curent, ST, DR, st;
int main()
{
    f >> n >> x;
    smax = curent = x;
    st = ST = DR = 1;
    for(int i = 2; i<=n; i++)
    {
        f >> x;
        if(curent + x > x)
            curent += x;
        else
            curent = x, st = i;

        if(curent > smax)
            smax = curent, ST = st, DR = i;
    }
    g << smax<<" "<<ST<<" "<< DR;
}