Pagini recente » Cod sursa (job #2880367) | Cod sursa (job #711998) | Cod sursa (job #28746) | Cod sursa (job #134248) | Cod sursa (job #2859020)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
long long N, i, x, p1 = 1, p2 = 1, lastS = 0, maxi = 0, sum, p1max, p2max;
int main()
{
fin >> N;
for(i = 1; i <= N; i++){
fin >> x;
sum = lastS + x;
if(sum > x){
lastS = sum;
p2 = i;
if(lastS > maxi){
maxi = lastS;
p1max = p1;
p2max = p2;
}
}else{
lastS = x;
p1 = p2 = i;
if(lastS > maxi){
maxi = lastS;
p1max = p1;
p2max = p2;
}
}
}
fout << maxi << ' ' << p1max << ' ' << p2max;
return 0;
}