Pagini recente » Cod sursa (job #1129820) | Cod sursa (job #2395337) | Cod sursa (job #460809)
Cod sursa(job #460809)
#include <cstdlib>
#include <fstream>
#define SIZE 540041
/*
*
*/
using namespace std;
ifstream in( "ssm.in" );
int idx;
char file[SIZE];
inline void read( int& x )
{
int sign=1;
while( file[idx] < '0' || file[idx] > '9' )
{
if( '-' == file[idx] )
sign=-1;
if( ++idx == SIZE )
{
idx=0;
in.read( file, SIZE );
}
}
for( x=0; file[idx] >= '0' && file[idx] <= '9'; )
{
x=x*10+file[idx]-'0';
if( ++idx == SIZE )
{
idx=0;
in.read( file, SIZE );
}
}
x*=sign;
}
int main( void )
{
int N, i, x, Smax, Smin, S, start=1, mstart=1, mend=1;
read(N); read(S);
Smin=Smax=S;
for( i=2; i <= N; ++i )
{
read(x);
S+=x;
if( Smax < S-Smin )
{
Smax=S-Smin;
mstart=start+1;
mend=i;
}
if( Smin > S )
{
Smin=S;
start=i;
}
}
ofstream out( "ssm.out" );
out<<Smax<<' '<<mstart<<' '<<mend<<'\n';
return EXIT_SUCCESS;
}