Pagini recente » Clasament simulare_republicana_2 | Cod sursa (job #3030114) | Cod sursa (job #3032456) | Cod sursa (job #284005) | Cod sursa (job #1686786)
#include <fstream>
#include <climits>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int main()
{
int x, n, i = 1, j, I, J, I1, s = 0, S = INT_MIN, nmax = INT_MIN;
fin >> n;
for (j = 1; j <= n; j++)
{
fin >> x;
if (x > nmax)
{
nmax = x;
I1 = j;
}
if ( s + x >= 0 )
{
s += x;
if ( S < s )
{
S = s;
I = i;
J = j;
}
}
else
{
i = j + 1;
s = 0;
}
}
if (S > INT_MIN)
fout << S << ' ' << I << ' ' << J << '\n';
else
fout << nmax << ' ' << I1 << ' ' << I1 << '\n';
fin.close();
fout.close();
return 0;
}