Pagini recente » Cod sursa (job #592188) | Cod sursa (job #147172) | Cod sursa (job #1866037) | Cod sursa (job #1129501) | Cod sursa (job #3283502)
#include <fstream>
#include <climits>
using namespace std;
ifstream in("ssm.in");
ofstream out("ssm.out");
int main()
{
int n;
in >> n;
int s_max = INT_MIN, s_c = 0;
int st, dr, st_max, dr_max;
st = dr = st_max = dr_max = 0;
for (int i = 1; i <= n; i++)
{
int x_i;
in >> x_i;
if (s_c >= 0)
{
s_c += x_i;
dr = i;
}
else
{
s_c = x_i;
st = dr = i;
}
if (s_c > s_max)
{
s_max = s_c;
dr_max = dr;
st_max = st;
}
}
out << s_max << ' ' << st_max << ' ' << dr_max;
in.close();
out.close();
return 0;
}