Pagini recente » Cod sursa (job #2950505) | Cod sursa (job #148038) | Cod sursa (job #1687140) | Cod sursa (job #1240955) | Cod sursa (job #2905725)
#include <iostream>
#include <fstream>
#include <limits>
int main()
{
std::ifstream fin("data.in");
std::ofstream fout("data.out");
int n, nr;
int s = -1, ind;
int s_max = std::numeric_limits<int>::min();
int ind_max = 0;
int end_max = std::numeric_limits<int>::max();
fin >> n;
for (int i = 1; i <= n; i++)
{
fin >> nr;
if (s >= 0)
s += nr;
else
{
s = nr;
ind = i;
}
if (s > s_max)
{
s_max = s;
ind_max = ind;
end_max = i;
}
if (s == s_max && (ind < ind_max || i - ind < end_max - ind_max))// && i - ind < end_max - ind_max)
{
s_max = s;
ind_max = ind;
end_max = i;
}
}
fout << s_max << ' ' << ind_max << ' ' << end_max << '\n';
}