Cod sursa(job #2643000)
| Utilizator | Data | 18 august 2020 10:27:19 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.6 kb |
#include <fstream>
#include <algorithm>
using namespace std;
int n, mmax, last, x, y, st, dr, provisory_st;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int main()
{
fin >> n >> x;
mmax = last = x; st = dr = provisory_st = 1;
for(int i = 2; i <= n; i++) {
fin >> x;
y = last;
last = max(last + x, x);
if(last == x && y != 0) {
provisory_st = i;
}
if(last > mmax) {
mmax = last;
dr = i; st = provisory_st;
}
}
fout << mmax << " " << st << " " << dr;
return 0;
}
