Pagini recente » Cod sursa (job #1935670) | Cod sursa (job #2959094) | Cod sursa (job #2489461) | Cod sursa (job #1332548) | Cod sursa (job #1042384)
#include <iostream>
#include <fstream>
using namespace std;
ifstream input("ssm.in");
ofstream output("ssm.out");
int N , x;
int S = 0;
int poz1 , poz2;
int SMAX = -1 * ( 1 << 20);
int poz1_max , poz2_max;
int main()
{
input >> N;
poz1 = 1;
poz2 = 0;
for (int i = 1; i <= N; i++)
{
input >> x;
S += x;
if (S > SMAX)
{
SMAX = S;
poz1_max = poz1;
poz2_max = i;
}
else if (S == SMAX)
{
if (poz1 < poz1_max)
{
poz1_max = poz1;
poz2_max = i;
}
else if (poz1 == poz1_max && i - poz1 + 1 < poz2_max - poz1_max + 1)
{
poz1_max = poz1;
poz2_max = i;
}
}
if (S < 0)
{
S = 0;
poz1 = i + 1;
}
else if (S < x)
{
poz1 = i;
S = x;
}
}
output << SMAX << " " << poz1_max << " " << poz2_max;
input.close();
output.close();
return 0;
}