Cod sursa(job #3283928)
| Utilizator | Data | 10 martie 2025 18:28:59 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 95 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.58 kb |
#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;
}
