Pagini recente » Cod sursa (job #528869) | Monitorul de evaluare | Cod sursa (job #1511221) | Monitorul de evaluare | Cod sursa (job #2687968)
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
FILE *fin, *fout;
int n, i, last, left, right, x, smax, leftmax, rightmax;
fin = fopen("ssm.in", "r");
fscanf(fin, "%d", &n);
fscanf(fin, "%d", &x);
last = x;
left = right = leftmax = rightmax = 0;
smax = x;
for (i = 1; i < n; i++) {
fscanf(fin, "%d", &x);
if (last >= 0) {
last += x;
right++;
}
else {
last = x;
left = right = i;
}
if (last > smax) {
smax = last;
leftmax = left;
rightmax = right;
}
}
fclose( fin );
fout = fopen("ssm.out", "w");
fprintf(fout, "%d %d %d", smax, leftmax + 1, rightmax + 1);
fclose( fout );
return 0;
}