Pagini recente » Cod sursa (job #2383598) | Cod sursa (job #138098) | Cod sursa (job #1134887) | Cod sursa (job #1083165) | Cod sursa (job #1145313)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin ("ssm.in");
ofstream fout ("ssm.out");
short int N, v[6000005];
void read()
{
int a,b, max = -7000000,k,x,y;
fin >> N;
a = x = 1; //Begin from x and set x to 1
b = y = 1; //End in y and set y to 1
fin >> k; //Reading one value
v[0] = k; //Setting the first element from v to value that has readed.
max = v[0]; //The maximum will be the first element readed.
for(int i = 1; i < N; i++)
{
fin >> k; //Reading one value
if(v[i-1] + k < k)
{//If the new sum is lower than the current element
v[i] = k;
a = i + 1;
b = i + 1;
}
else
{
v[i] = v[i-1] + k;
b = i + 1;
}
if(v[i] > max)
{
max = v[i];
x = a;
y = b;
}
}
fout << max << " " << x << " " << y;
}
int main()
{
read();
return 0;
}