Pagini recente » Cod sursa (job #1125494) | Cod sursa (job #2856939) | Cod sursa (job #2755941) | Cod sursa (job #1596508) | Cod sursa (job #1246819)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream in("ssm.in");
ofstream out("ssm.out");
int d[6000003];
int a[6000005];
int main()
{int n,i,sf,best,cb;
in>>n;
in>>a[1];
d[1]=a[1];
best=d[1];
for(i=2;i<=n;i++)
{
in>>a[i];
d[i]=a[i];
d[i]=max(d[i],d[i-1]+a[i]);
if(best<d[i])
{
best=d[i];
sf=i;
}
}
cb=best;
for(i=sf;cb>=0;i--)
{
if(cb)
cb=cb-a[i];
else
{while(!a[i])
i--; break;}
out<<i<<" ";
//if(cb==0)
//out<<i<<" ";
}
out<<best<<" "<<i+1<<" "<<sf<<'\n';
return 0;
}