Cod sursa(job #2583479)

Utilizator alexboat10759Alex Mateescu alexboat10759 Data 18 martie 2020 12:53:04
Problema Subsecventa de suma maxima Scor 35
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.6 kb
#include <iostream>
#include <fstream>

using namespace std;

int v[100002],s[100002];

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

    int n,poz=0,k,maxx=-1,minn=2000000000,poz1,poz2;
    fin>>n;
    for(int i=1;i<=n;i++)
    {
        fin>>v[i];
        s[i]=s[i-1]+v[i];
        if(minn>s[i])
        {
            minn=s[i];
            poz1=i+1;
        }

    }
   for(int i=1;i<=n;i++)
   {
       if(maxx<s[i]-minn)
       {
           maxx=s[i]-minn;
           poz2=i;
       }
   }
   fout<<maxx<<" "<<poz1<<" "<<poz2;
    return 0;
}