Pagini recente » Cod sursa (job #1049748) | Cod sursa (job #1155435)
#include <fstream>
using namespace std;
int a[6000000];
int main()
{
ifstream in("ssm.in");
ofstream out("ssm.out");
int n, i, sc, stc, stmax, drmax, smax;
in >> n;
for ( i = 1; i <= n; i++ )
in >> a[i];
smax = a[1];
stmax = 1;
drmax = 1;
sc = 0;
for ( i = 1; i <= n; i++ )
{
if ( sc < 0 )
{
sc = 0;
stc = i;
}
sc+= a[i];
if ( sc > smax)
{
smax = sc;
stmax = stc;
drmax = i;
}
}
out << smax << ' ' << stmax <<' '<< drmax;
return 0;
}