Pagini recente » Cod sursa (job #954722) | Borderou de evaluare (job #2510141) | Cod sursa (job #1399913) | Cod sursa (job #1902309) | Cod sursa (job #1854810)
#include <fstream>
#define nmax 6000001
using namespace std;
ifstream fin ( "ssm.in" );
ofstream fout ( "ssm.out" );
int a[nmax], lg[nmax];
int main()
{ int n, i, s, smax, imax;
fin >> n;
for ( i = 1; i <= n; i++ )
fin >> a[i];
fin.close();
s = a[1];
lg[1] = 1;
smax = s;
imax = 1;
for ( i = 2; i <= n; i++ )
if ( s >= 0 )
{ s = s + a[i];
lg[i] = lg[i-1] + 1;
if ( s > smax )
{ smax = s;
imax = i;
}
else if ( s == smax )
if ( lg[i] < lg[imax] )
imax = i;
}
else
{ s = a[i];
lg[i] = 1;
if ( s > smax )
{ smax = s;
imax = i;
}
else if ( s == smax )
if ( lg[i] < lg[imax] )
imax = i;
}
fout << smax << " " << imax - lg[imax] + 1 << " " << imax << "\n";
fout.close();
return 0;
}