Pagini recente » Cod sursa (job #551909) | Borderou de evaluare (job #521000) | Cod sursa (job #196031) | Cod sursa (job #573811) | Cod sursa (job #517339)
Cod sursa(job #517339)
#include <fstream>
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
const int INF = 2000000000;
int best = -INF,a;
int best_max = -INF,a_best_max,b_best_max;
int main()
{
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;
return 0;
}