Pagini recente » Cod sursa (job #2746128) | Cod sursa (job #1512133) | Cod sursa (job #2490746) | Cod sursa (job #3127600) | Cod sursa (job #1372037)
#include <fstream>
#define IN "ssm.in"
#define OUT "ssm.out"
using namespace std;
ifstream fin(IN);
ofstream fout(OUT);
int i, n, a[101], x, y, bestS, best[101];
bool ok;
int main()
{
fin >> n;
for(i = 1; i <= n; ++i)
fin >> a[i];
bestS = a[1];
for(i = 1; i <= n; ++i)
{
best[i] = a[i];
if(best[i] < best[i-1] + a[i])
{
best[i] = best[i-1] + a[i];
if(ok == false)
{
x = i;
ok = true;
x++;
}
}
if(bestS < best[i])
{
bestS = best[i];
y = i;
}
}
fout << bestS << ' ' << x << ' ' << y << '\n';
return 0;
}