Cod sursa(job #2290525)
| Utilizator | Data | 26 noiembrie 2018 17:11:27 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.55 kb |
#include <fstream>
using namespace std;
ifstream in("ssm.in");
ofstream out("ssm.out");
int main()
{
int n, x;
int smax = 1 << 31;
int ei, ef;
int sc = 0, j;
in >> n;
for(int i = 1; i <= n; i++)
{
in >> x;
if(sc + x >= x)
{
sc += x;
}
else
{
sc = x;
j = i;
}
if(sc > smax)
{
smax = sc;
ei = j;
ef = i;
}
}
out << smax << ' ' << ei << ' ' << ef << '\n';
return 0;
}
