Pagini recente » Cod sursa (job #647070) | Cod sursa (job #1485341) | Cod sursa (job #1845122) | Cod sursa (job #1971295) | Cod sursa (job #723848)
Cod sursa(job #723848)
#include <fstream>
int main (void)
{
std::ifstream input("ssm.in");
unsigned int n;
input >> n;
signed int max;
input >> max;
unsigned int start(1),last(1);
signed int suma(max),x;
for (unsigned int i(2), begin(1), end(1) ; i <= n ; ++i)
{
input >> x;
if (suma >= 0)
{
suma += x;
++end;
}
else
{
suma = x;
begin = end = i;
}
if (suma > max)
{
max = suma;
start = begin;
last = end;
}
}
input.close();
std::ofstream output("ssm.out");
output << max << ' ' << start << ' ' << last << '\n';
output.close();
return 0;
}