Pagini recente » Cod sursa (job #953529) | Cod sursa (job #143128) | Cod sursa (job #1627211) | Cod sursa (job #2299863) | Cod sursa (job #784200)
Cod sursa(job #784200)
#include<cstdio>
#define NMAX 6000005
int A[NMAX];
int N, K;
int posStart, posEnd;
int sumMax;
int main()
{
freopen("ssm.in","r",stdin);
freopen("ssm.out","w",stdout);
scanf("%d", &N);
for(int i = 1; i <= N; i++)
scanf("%d",&A[i]);
int max = A[1];
posStart = 1;
posEnd = 1;
int currentSum = 0;
for(int i = 1; i <= N; i++)
{
int j = i;
while(j <= N && currentSum + A[j] >= 0)
{
currentSum = currentSum + A[j];
if(currentSum > max)
{
max = currentSum;
posStart = i;
posEnd = j;
}
j++;
}
if(j <= N)
if(A[j] > max)
{
max = A[j];
posStart = j;
posEnd = j;
}
i = j;
currentSum = 0;
}
printf("%d %d %d\n", max, posStart, posEnd);
return 0;
}