Pagini recente » Cod sursa (job #2714108) | Cod sursa (job #3188679) | Cod sursa (job #1324533) | Cod sursa (job #2963829) | Cod sursa (job #3260133)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fi("ssm.in");
ofstream fo("ssm.out");
int main()
{
int n,x,s=0,ii=0,is=0,mx=-1000000,smx=0,ok=0,ok2=1;
fi>>n;
for(int i=1;i<=n;i++){
fi>>x;
if(x>mx)mx=x;
s=s+x;
if(smx<s){
smx=s,ok=1;
if(ok2==1)ii=i,ok2=0;
}
if(smx==s)is=i;
if(s<0)s=0,ok2=1;///ii++;
cout<<smx<<" ";
}
cout<<endl;
if(ok==0)fo<<mx;
else fo<<smx<<" "<<ii-1<<" "<<is;
}