Pagini recente » Cod sursa (job #120145) | Cod sursa (job #20208) | Cod sursa (job #329971) | Cod sursa (job #486153) | Cod sursa (job #1854804)
#include <fstream>
#define top 6000005
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int a[top],best,bestmax=0,pozbestmax,lg[top];
int main()
{
int n,i;
fin>>n;
for(i=1; i<=n; i++) fin>>a[i];
fin.close();
best=a[1];
bestmax=a[1];
pozbestmax=1;
lg[1]=1;
for(i=2; i<=n; i++)
{
if(best+a[i]>a[i]) { best=best+a[i];
lg[i]=lg[i-1]+1;
if(best>bestmax) { bestmax=best; pozbestmax=i;}
else if(best==bestmax && lg[i]<lg[pozbestmax]) { bestmax=best; pozbestmax=i;}
}
else { best=a[i];
lg[i]=1;
if(best>bestmax) { bestmax=best; pozbestmax=i;}
}
}
fout<<bestmax<<' '<<pozbestmax-lg[pozbestmax]+1<<' '<<pozbestmax<<'\n';
fout.close();
fin.close();
return 0;
}