Pagini recente » Cod sursa (job #888442) | Cod sursa (job #3039982) | Cod sursa (job #2965313) | Cod sursa (job #1326411) | Cod sursa (job #2122165)
#include <fstream>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int best[6000100];
int a[6000010];
int main()
{
int i,bestSum=-6000100,N,st=1,dr=1,stp=1;
fin>>N;
for(i = 1; i <= N; i++){
fin>>a[i];
}
for(i = 1; i <= N; i++){
if(a[i] < best[i-1] + a[i]){
best[i] = a[i] + best[i-1];
}
else{
best[i] = a[i];
stp = i;
}
if(bestSum < best[i]){
bestSum = best[i];
dr = i;
st = stp;
}
}
fout<<bestSum<<" "<<st<<" "<<dr<<"\n";
}