Pagini recente » Cod sursa (job #119129) | Cod sursa (job #200209) | Cod sursa (job #2210847) | Cod sursa (job #2098166) | Cod sursa (job #517317)
Cod sursa(job #517317)
#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;
}