Pagini recente » Cod sursa (job #815811) | Cod sursa (job #1866732) | Cod sursa (job #95531) | Cod sursa (job #1012004) | Cod sursa (job #2701319)
#include <fstream>
using namespace std;
long long 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;
}