Pagini recente » Cod sursa (job #1352960) | Monitorul de evaluare | Cod sursa (job #2583492)
#include <iostream>
#include <fstream>
using namespace std;
int A[100002];
int main()
{
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int n;
fin>>n;
for(int i=1; i<=n; i++)
{
fin>>A[i];
}
int st, dr, Smax = -2000000000, S = -1, start;
for(int i = 1 ; i <= n ; ++ i)
{
if(S < 0)
{
S = 0;
start = i;
}
S += A[i];
if(S > Smax)
{
Smax = S;
st = start;
dr = i;
}
}
fout << Smax << " ";
fout << st << " " << dr;
return 0;
}