Pagini recente » Cod sursa (job #42257) | Cod sursa (job #1962651) | Cod sursa (job #2217339) | Cod sursa (job #1592818) | Cod sursa (job #2122115)
#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=0,dr=0;
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];
if(bestSum < best[i]){
bestSum = best[i];
dr = i;
}
}
else{
best[i] = a[i];
if(!(st<dr && dr != 0))
st = i;
}
if(bestSum < best[i]) bestSum = best[i];
}
fout<<bestSum<<" "<<st<<" "<<dr<<"\n";
}