Cod sursa(job #2227154)

Utilizator Moise_AndreiMoise Andrei Moise_Andrei Data 31 iulie 2018 13:29:54
Problema Subsecventa de suma maxima Scor 85
Compilator cpp Status done
Runda Arhiva educationala Marime 0.53 kb
#include <bits/stdc++.h>
#define int long long
using namespace std;
ifstream in("ssm.in");
ofstream out("ssm.out");
int32_t main()
{
    int n;
    in >> n;
    int mx = 0;
    int mx2 = 0;
    int poz1 = 0, poz2 = 0;
    for(int i = 1; i <= n; i ++)
    {
        int a;
        in >> a;
        if(mx + a < a)
            poz1 = i;
        mx = max(mx + a, a);
        if(mx2 < mx)
        {
            poz2 = i;
            mx2 = mx;
        }
    }
    out << mx2 << " " << poz1 << " " << poz2;
    return 0;
}