Cod sursa(job #517317)
| Utilizator | Data | 28 decembrie 2010 13:37:18 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 95 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.55 kb |
#include <fstream>
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
int best=-1,a;
int best_max = -1,a_best_max,b_best_max;
void citire()
{
int nr,n;
f>>n;
for (int i = 1; i <= n; ++i)
{
f>>nr;
if (best >= 0) //best[i] = max(best[i-1] + nr,nr);
best = best + nr;
else
{
best = nr;
a = i;
}
if (best > best_max)
{
best_max = best;
a_best_max = a;
b_best_max = i;
}
}
g<<best_max<<" "<<a_best_max<<" "<<b_best_max;
}
int main()
{
citire();
return 0;
}
