Pagini recente » Cod sursa (job #1979761) | Cod sursa (job #1366223) | Cod sursa (job #1880815) | Cod sursa (job #1713140) | Cod sursa (job #2617548)
#include <fstream>
#define max(a, b) ((a > b) ? a : b)
int v[6000005], d[6000005];
int main() {
std::ifstream fin("ssm.in");
std::ofstream fout("ssm.out");
int n, i, max = 0, maxIndex, startIndex, temp;
fin >> n;
for(i = 1; i <= n; ++i)
fin >> v[i];
for(i = 2; i <= n; ++i) {
d[i] = max(d[i-1] + v[i], v[i]);
if(d[i] > max) {
max = d[i];
maxIndex = i;
}
}
temp = max;
i = maxIndex;
while(temp) {
temp -= v[i];
--i;
}
fout << max << ' ' << i+1 << ' ' << maxIndex;
}