Pagini recente » Cod sursa (job #875877) | Cod sursa (job #1046191) | Cod sursa (job #3191610) | Cod sursa (job #2104354) | Cod sursa (job #1248473)
#include <fstream>
#include <vector>
int main()
{
std::ifstream fin("ssm.in");
std::ofstream fout("ssm.out");
int N;
fin >> N;
std::vector<int> elems(N);
for (int i = 0; i < N; ++i)
fin >> elems[i];
fin.close();
int max = elems[0];
int current_max = elems[0];
int start = 0, end = 0;
int max_start, max_end;
for (std::vector<int>::const_iterator it = elems.cbegin() + 1;
it != elems.cend(); ++it) {
if (current_max > 0) {
current_max += *it;
end++;
} else {
current_max = *it;
start = end = it - elems.cbegin();
}
if (current_max > max) {
max = current_max;
max_start = start;
max_end = end;
}
}
fout << max << " " << max_start + 1 << " " << max_end + 1;
fout.close();
return 0;
}