Cod sursa(job #2377273)
| Utilizator | Data | 9 martie 2019 12:45:08 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.55 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin ("ssm.in");
ofstream fout ("ssm.out");
int main()
{
long long sc = 0, smax = - 20000000;
int x, umax, pmax, n, pc;
fin >> n;
for (int i = 1; i <= n; i++)
{
fin >> x;
if (sc < 0)
{
sc = x;
pc = i;
}else{
sc += x;
}
if (sc > smax)
{
smax = sc;
pmax = pc;
umax = i;
}
}
fout << smax << " " << pmax << " " << umax;
return 0;
}
