Pagini recente » Cod sursa (job #1189826) | Cod sursa (job #653818) | Cod sursa (job #2201570) | Cod sursa (job #2952196) | Cod sursa (job #2951166)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int n[6000005], bonga[6000005], y, smax = 0, st, dr;
int main()
{
fin >> y;
fin >> n[1];
bonga[1] = n[1];
for(int i = 2; i <= y; i++){
fin >> n[i];
bonga[i] = n[i];
}
for(int i =1 ;i <=y; i++){
if(bonga[i] < n[i] + bonga[i - 1]){
bonga[i] = bonga[i - 1] + n[i];
}
if(smax < bonga[i]){
smax = bonga[i];
dr = i;
}
}
for(int i = dr; i >= 1; i--){
if(bonga[i] <= 0){
st = i;
break;
}
}
fout << smax << " " << st + 1 << " " << dr;
return 0;
}