Pagini recente » Cod sursa (job #553214) | Cod sursa (job #1350814) | Cod sursa (job #57769) | Cod sursa (job #3198372) | Cod sursa (job #3283928)
#include <fstream>
#include <algorithm>
using namespace std;
using ll = long long;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
const int DIM = 6e6 + 5;
ll a[DIM];
int n;
void Secv();
int main()
{
fin >> n;
for (int i = 1; i <= n; ++i)
fin >> a[i];
Secv();
}
void Secv()
{
ll s{}, smax{};
int i = 1, I = 1, J = 1;
for (int j = 1; j <= n; ++j)
{
s += a[j];
if (s >= 0)
{
if (s > smax)
{
smax = s;
I = i, J = j;
}
}
else
{
i = j + 1;
s = 0;
}
}
fout << smax << ' ' << I << ' ' << J;
}