Pagini recente » Cod sursa (job #889296) | Cod sursa (job #1879574) | Cod sursa (job #2796420) | Cod sursa (job #2240334) | Cod sursa (job #443536)
Cod sursa(job #443536)
/*
* File: main.cpp
* Author: VirtualDemon
*
* Created on April 17, 2010, 1:20 PM
*/
#include <cstdlib>
#include <fstream>
#define SIZE 8219
/*
*
*/
using namespace std;
ifstream 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 )
{
in.read( file, SIZE );
idx=0;
}
}
x=0;
while( file[idx] >= '0' && file[idx] <= '9' )
{
x=x*10+file[idx]-'0';
if( ++idx == SIZE )
{
in.read( file, SIZE );
idx=0;
}
}
x*=sign;
}
int main(int argc, char** argv)
{
int N, i, j=1, x, min, max, minstart=1, S, Smax, mstart=1, mend=1;
in.open( "ssm.in" );
read(N);
read(x);
for( min=max=S=Smax=x, i=2; i <= N; ++i )
{
read(x);
if( max < x )
max=x, j=i;
S+=x;
if( S > Smax )
{
Smax=S;
mend=i;
mstart=1;
}
if( S-min > Smax )
{
Smax=S-min;
mend=i;
mstart=minstart+1;
}
if( min > S )
{
min=S;
minstart=i;
}
}
ofstream out( "ssm.out" );
if( Smax > max )
out<<Smax<<' '<<mstart<<' '<<mend<<'\n';
else out<<max<<' '<<j<<' '<<j<<'\n';
return EXIT_SUCCESS;
}