Pagini recente » Cod sursa (job #1713926) | Cod sursa (job #1183972) | Cod sursa (job #145256) | Cod sursa (job #2672539) | Cod sursa (job #1100492)
#include<fstream>
int v[6000005];
int best[6000005];
using namespace std;
int main()
{
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int n,min,bestSum,x;
fin>>n;
for(int i=1;i<=n;++i)
fin>>v[i];
if(n==1)
{
fout<<v[1]<<" 1 1";
return 0;
}
bestSum=v[1];
int a,b,aa;
a=0;
b=0;
for(int i=1;i<=n;++i)
{
best[i]=v[i];
if(best[i]<best[i-1]+v[i])
best[i]=best[i-1]+v[i];
else if(best[i]>best[i-1]+v[i])
aa=i;
if(bestSum<best[i])
{
bestSum=best[i];
b=i;
a=aa;
}
}
fout<<bestSum<<" "<<a<<" "<<b;
return 0;
}