Pagini recente » Cod sursa (job #1370423) | Cod sursa (job #378102) | Cod sursa (job #688661) | Cod sursa (job #2882388) | Cod sursa (job #2512965)
#include <cstdio>
int N;
int main() {
freopen("ssm.in", "r", stdin);
freopen("ssm.out", "w", stdout);
scanf("%d", &N);
int partialSum = 0, lowestPartialSum = 0, lowestPartialSumStart = 0;
int largestSum, largestSumStart, largestSumEnd;
int x;
for (int i = 1; i <= N; i++) {
scanf("%d", &x);
if (i == 1) {
largestSum = x;
largestSumStart = largestSumEnd = 1;
}
partialSum += x;
if (partialSum - lowestPartialSum > largestSum) {
largestSum = partialSum - lowestPartialSum;
largestSumStart = lowestPartialSumStart + 1;
largestSumEnd = i;
}
if (partialSum < lowestPartialSum) {
lowestPartialSum = partialSum;
lowestPartialSumStart = i;
}
}
printf("%d %d %d\n", largestSum, largestSumStart, largestSumEnd);
return 0;
}