Cod sursa(job #1939010)

Utilizator al-ghabaghbi_anisAl Ghabaghbi Anis al-ghabaghbi_anis Data 25 martie 2017 13:19:35
Problema Subsecventa de suma maxima Scor 85
Compilator cpp Status done
Runda Arhiva educationala Marime 0.49 kb
#include<fstream>
#include<climits>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int s[6000003];
int main()
{
int n,a,i,x,y,z;
fin>>n;
for(i=1;i<=n;i++)
{
fin>>a;
s[i]=s[i-1]+a;
}
int Min=INT_MAX;
int Max=INT_MIN;
for(i=1;i<=n;i++)
    {
    if(Min>s[i-1])
        {
        Min=s[i-1];
        x=i;
        }
    if(s[i]-Min>Max && i!=1)
        {
        Max=s[i]-Min;
        y=i;
        }
    z=x;
    }
fout<<Max<<" "<<z<<" "<<y;
}