Pagini recente » Cod sursa (job #225243) | Cod sursa (job #2708213) | Cod sursa (job #2383581) | Cod sursa (job #3251527) | Cod sursa (job #2320272)
#include <fstream>
using namespace std;
ifstream cin("ssm.in");
ofstream cout("ssm.out");
int main()
{
int n, maxim, maxG, dr, st, drG, stG;
cin >> n;
int v[n];
for (int i = 0; i < n; ++i)
cin >> v[i];
maxim = maxG = v[0];
dr = st = 0;
for (int i = 1; i < n; ++i)
{
if (v[i] > maxim + v[i])
{
st = dr = i;
maxim = v[i];
}
else
{
maxim = v[i] + maxim;
st++;
}
if (maxim >= maxG)
{
maxG = maxim;
stG = st;
drG = dr;
}
}
cout << maxG << " " << drG + 1<< " " << stG + 1;
return 0;
}