Cod sursa(job #3244712)
| Utilizator | Data | 26 septembrie 2024 09:32:08 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.67 kb |
#include<bits/stdc++.h>
using namespace std;
ifstream fcin("ssm.in");
ofstream fcout("ssm.out");
const int N = 6e6 + 5;
int v[N], n;
int main()
{
int k, s, smax, st, stmax, drmax;
fcin >> n;
for (int i = 1; i <= n; i++)
fcin >> v[i];
s = 0;
smax = INT_MIN;
st = 1;
stmax = drmax = 0;
for (int i = 1; i <= n; i++)
{
s += v[i];
if (s > smax)
{
smax = s;
stmax = st;
drmax = i;
}
if (s < 0)
{
s = 0;
st = i + 1;
}
}
fcout << smax << ' ' << stmax << ' ' << drmax;
return 0;
}
