Pagini recente » Cod sursa (job #1075639) | Cod sursa (job #1298378) | Cod sursa (job #1789839) | Cod sursa (job #1054815) | Cod sursa (job #830073)
Cod sursa(job #830073)
#include <fstream>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int n,i,a[10000],s[10000]={0},maxx,im,jm;
int main()
{
fin>>n;
for(i=1;i<=n;i++)
fin>>a[i];
maxx = a[1];
for(i=1;i<=n;i++)
{
s[i]=a[i];
if(s[i]<s[i-1]+a[i]) s[i]=s[i-1]+a[i];
if(s[i]>maxx)
{ maxx=s[i];
jm=i;
}
}
fout<<maxx<<" ";
im=jm;
while(im>0 && s[im]>=0) im--;
im++;
fout<<im<<" "<<jm;
return 0;
}