Pagini recente » Cod sursa (job #1191168) | Solutii preONI 2008, Runda 1 | Cod sursa (job #1884790) | Cod sursa (job #2894872) | Cod sursa (job #2748874)
#include <bits/stdc++.h>
using namespace std;
int v[6000001];
int main()
{
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int n;
fin>>n;
for(int i=1; i<=n;i++)
fin>>v[i];
int bestSum=-2000000000, bestLeftIndex, bestRightIndex, currentSum=0, currentLeftIndex=1;
for(int i=1;i<=n;i++){
currentSum+= v[i];
if(currentSum > bestSum){
bestSum = currentSum;
bestLeftIndex = currentLeftIndex;
bestRightIndex = i;
}
if(currentSum < 0){
currentSum = 0;
currentLeftIndex = i + 1;
}
}
fout<< bestSum <<" "<< bestLeftIndex <<" "<< bestRightIndex;
}