Cod sursa(job #2617548)
| Utilizator | Data | 21 mai 2020 22:30:38 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 75 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.6 kb |
#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;
}