Pagini recente » Cod sursa (job #2951326) | Cod sursa (job #2799107) | Cod sursa (job #116210) | Cod sursa (job #748929) | Cod sursa (job #2981525)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;
ifstream fin("test.in");
ofstream fout("test.out");
int main()
{
long long max_sum = -100000;
long long current_sum = 0;
int begin, end, start_pos = 1;
int n, y;
fin >> n;
for(int i = 1; i <= n; i++)
{
fin >> y;
current_sum += y;
if(current_sum < 0)
{
current_sum = 0;
start_pos = i + 1;
}
if(current_sum > max_sum)
{
max_sum = current_sum;
end = i;
begin = start_pos;
}
}
cout << max_sum << ' ' << begin << ' ' << end << '\n';
}