Pagini recente » Cod sursa (job #2714239) | Cod sursa (job #454643) | Cod sursa (job #2521291) | Cod sursa (job #1749042) | Cod sursa (job #1508935)
#include <iostream>
#include <fstream>
#define NMAX 6000002
using namespace std;
ifstream in("ssm.in");
ofstream out("ssm.out");
int n, a[NMAX],smax,s,x,xx,y,yy,l,lmax;
int main()
{
in >> n;
for(int i=1;i<=n;i++)
in >> a[i];
s = a[1],smax=a[1],l=1;
for(int i=2;i<=n;i++)
{
if(s>=0)
{
s =s + a[i];
l++;
}
else
{
s = a[i];
x = i;
l=1;
}
if(s>smax)
{
smax = s;
xx = x;
lmax = l;
}
}
out << smax << " " << xx << " " << lmax+xx-1;
return 0;
}