Pagini recente » Istoria paginii runda/simulare2016_lasm | Istoria paginii runda/pregatire_cls9_oji | Istoria paginii runda/cnitv_baraj_2 | Istoria paginii runda/kontrollarbeit | Cod sursa (job #2079769)
#include <fstream>
using namespace std;
ifstream in("ssm.in");
ofstream out("ssm.out");
int main()
{
int n, i, ii=-1, is, x, smax=-1, s=0, lung;
in>>n;
for (i=1; i<=n; i++)
{
in>>x;
if (s+x>=0)
{
s+=x;
if(ii==-1)
ii=i;
if (s>smax)
{
lung=is-ii+1;
is=i;
smax=s;
}
else if (s==smax)
if (i-ii+1<lung)
{
is=i;
lung=is-ii+1;
}
}
else
{
ii=-1;
s=0;
}
}
out<<smax<<" "<<ii<<" "<<is;
return 0;
}