Cod sursa(job #2964273)

Utilizator Ruxandra009Ruxandra Vasilescu Ruxandra009 Data 12 ianuarie 2023 19:01:04
Problema Subsecventa de suma maxima Scor 80
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.5 kb
#include <bits/stdc++.h>
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
const int NR = 2000000005;
int n, x, s, Min = NR, Max, p1, p2;
int main()
{
    f >> n;
    for(int i = 1; i <= n; i ++)
    {
        f >> x;
        s += x;
        if(s < Min)
        {
            Min = s;
            p1 = i + 1;
        }
        if(s > Max)
        {
            Max = s;
            p2 = i;
        }
    }

    g << Max - Min << " " << p1 << " " << p2;
    return 0;
}