Pagini recente » Cod sursa (job #304566) | Profil CostinMara | Istoria paginii utilizator/ionanghelina | Niciomare | Cod sursa (job #3283491)
#include <fstream>
using namespace std;
ifstream in("ssm.in");
ofstream out("ssm.out");
const int INF = 2e9;
int main()
{
int n;
in >> n;
int s_max = -INF, s_c = 0;
int st, dr, st_max, dr_max;
st = dr = st_max = dr_max = 0;
for (int i = 0; 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;
}
}
dr_max++;
st_max++;
out << s_max << ' ' << st_max << ' ' << dr_max;
in.close();
out.close();
return 0;
}