Pagini recente » Cod sursa (job #3196205) | Cod sursa (job #45311) | Cod sursa (job #2838800) | Cod sursa (job #2616575)
#include <fstream>
using namespace std;
ifstream cin( "ssm.in" );
ofstream cout( "ssm.out" );
int read()
{
int semn = 1;
char x;
cin.get( x );
while( isspace( x ) )
cin.get( x );
if( x == '-' ){
semn = -1;
cin.get( x );
}
long long nr = 0;
while( isdigit( x ) ){
nr = nr * 10 + x - '0';
cin.get( x );
}
return semn * nr;
}
int main()
{
int n, x, ant, i, stmax, drmax, st;
long long s, maxx;
n = read();
x = read();
s = x;
ant = x;
maxx = -2000000000;
stmax = 0;
drmax = n - 1;
st = 0;
for( i = 1; i < n; i++ ){
x = read();
s = max( s + x, (long long)x );
if( s == x )
if( ant == 0 )
st = i - 1;
else
st = i;
//cout << st << ' ';
if( maxx < ( s ) ){
maxx = s, stmax = st, drmax = i;
}
ant = x;
}
cout << maxx << ' ' << stmax + 1 << ' ' << drmax + 1;
return 0;
}