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