Pagini recente » Cod sursa (job #3259491) | Cod sursa (job #2898420) | Cod sursa (job #3245973) | Cod sursa (job #2437989) | Cod sursa (job #2638722)
#include <iostream>
#include <fstream>
#include <climits>
#define DMAX 6000001
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int v[DMAX];
bool testareNegativ(int n)
{
for(int i = 1; i <= n; i++)
{
if(v[i] > 0)
{
return 0;
}
}
return 1;
}
void MaxSumSuba(int v[], int n)
{
int local_max = 0;
int global_max = INT_MIN;
int start = 0;
int ennd = 0;
int tempstart = 0;
for(int i = 1; i <= n; i++)
{
local_max = max(v[i], v[i] + local_max);
if(local_max < 0 && testareNegativ(n))
{
int j = i - 1;
tempstart = j + 1;
}
else if(local_max < 0)
{
tempstart = i + 1;
}
if(local_max > global_max)
{
global_max = local_max;
ennd = i;
start = tempstart;
}
}
fout << global_max << ' ' << start << ' ' << ennd;
}
int main()
{
int n;
fin >> n;
for(int i = 1; i <= n; i++)
fin >> v[i];
MaxSumSuba(v, n);
return 0;
}