Cod sursa(job #3332492)
| Utilizator | Data | 6 ianuarie 2026 23:02:07 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 95 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.68 kb |
#include <bits/stdc++.h>
#define int long long
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int n;
signed main()
{
fin >> n;
int l, r, max, curl, curmax;
fin >> curmax;
curl = 1;
l = curl, r = 1, max = curmax;
for (int i = 2; i <= n; i++)
{
int x;
fin >> x;
if (curmax + x > x)
{
curmax += x;
}
else
{
curmax = x;
curl = i;
}
if (curmax > max)
{
l = curl;
r = i;
max = curmax;
}
}
fout << max << " " << l << " " << r;
return 0;
}