Pagini recente » Cod sursa (job #865868) | Cod sursa (job #915218) | Cod sursa (job #352613) | Cod sursa (job #83819) | Cod sursa (job #2447725)
#include <fstream>
using namespace std;
ifstream in("ssm.in");
ofstream out("ssm.out");
int x,n,length,last,first;
long long s,smax=-900000000000;
int main()
{
in >> n;
for(int i=1;i<=n;i++)
{
in>>x;
if(s+x<x)
{
length=1;
s=x;
if(s>smax){
smax=s;
last=i;
first=i-length+1;
}
}
else
{
s+=x;
length++;
if(s>smax){
smax=s;
last=i;
first=i-length+1;
}
}
}
out<<smax<<" "<<first<<" "<<last;
return 0;
}