Pagini recente » Cod sursa (job #2889923) | Cod sursa (job #3220864) | Cod sursa (job #2998525) | Cod sursa (job #753118) | Cod sursa (job #1416203)
#include <fstream>
#include <iostream>
//#include <cstring>
#define dimmax 6000000
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
bool numerepozitive=false;
int n;
int a[dimmax],best[dimmax],bestSum=0,i=0,auxpozibestSum;
int pozibestSum,pozsbestSum;
int main()
{
/*bool numerepozitive=false;
int n;
int a[dimmax],best[dimmax],bestSum=0,i=0,auxpozibestSum;
int pozibestSum,pozsbestSum;*/
fin>>n;
//memset(best,0,sizeof(best));
//memset(a,0,sizeof(a));
for(i=0;i<=n;i++)
{
fin>>a[i];
if(a[i]>0)
numerepozitive=true;
}
bestSum=a[0];
pozibestSum=0;pozsbestSum=0;
// fout<<best[i]<<' ';
for(i=0;i<n;i++)
{
best[i]=a[i];
if (best[i]<best[i-1]+a[i])
{
best[i]=best[i-1]+a[i];
// fout<<best[i]<<' ';
}
if(best[i-1]<0 and numerepozitive==true)
{
/* pozicrt=i;*/
pozibestSum=i;
}
if (bestSum<best[i])
{
bestSum=best[i];
pozsbestSum=i;
if(best[i-1]<0 and numerepozitive==false)
{
/* pozicrt=i;*/
pozibestSum=i;
}
}
}
fout<<bestSum<<' '<<pozibestSum+1<<' '<<pozsbestSum+1;
fin.close(); fout.close();
return 0;
}