Pagini recente » Cod sursa (job #3134410) | Cod sursa (job #475806) | Cod sursa (job #1865381) | Cod sursa (job #1048338) | Cod sursa (job #2668717)
#include <bits/stdc++.h>
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
int nr;
int maxsum = -2000000009;
int n;
int ind1, ind2;
int summ;
int nrpoz;
int nrmax=-2000000009,poznrmax;
int ind1max, ind2max;
int main()
{
f >> n;
ind1 = 1;
ind2 = 1;
for (int i=1;i<=n;i++) {
f >> nr;
if (nr > nrmax) {
nrmax = nr;
poznrmax = i;
}
summ += nr;
ind2 = i;
if (summ < 0) {
ind1 = i+1;
summ = 0;
}
else {
if (summ > maxsum) {
maxsum = summ;
ind1max = ind1;
ind2max = ind2;
}
}
}
if (nrmax < 0) {
g << nrmax << " " << poznrmax << " " << poznrmax;
}
else {
g << maxsum << " " << ind1max << " " << ind2max;
}
return 0;
}