Pagini recente » Cod sursa (job #1249817) | Cod sursa (job #2054363) | Cod sursa (job #2287670) | Cod sursa (job #2979426) | Cod sursa (job #849673)
Cod sursa(job #849673)
#include<fstream>
using namespace std;
long long int n,a[6000000],i,ic,sc,pc,sf,max1;
int main ()
{
ifstream f("ssm.in");
ofstream g("ssm.out");
f>>n;
for(i=1;i<=n;i++)
f>>a[i];
max1=-2900000;
sc=a[n];
ic=n; sf=n;
pc=n;
for(i=n-1;i>=1;i--)
{
if(sc>=0) { sc=sc+a[i]; }
else { sc=a[i]; pc=i; }
if(sc>max1) {max1=sc; sf=pc; ic=i; }
}
sc=0;
for(i=ic;i<=sf;i++)
sc=sc+a[i];
g<<sc<<" "<<ic<<" "<<sf;
}