Cod sursa(job #3299846)
| Utilizator | Data | 10 iunie 2025 22:03:20 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.59 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("ssm.in");
ofstream fout ("ssm.out");
const int nmax=6e6+5;
int dp[nmax], rez=INT_MIN, st, dr;
int main ()
{
int n, poz=1;
fin >> n;
for (int i=1; i<=n; i++)
{
int x;
fin >> x;
dp[i]=dp[i-1];
if (dp[i]<0)
{
dp[i]=0;
poz=i;
}
dp[i]+=x;
if (dp[i]>rez)
{
rez=dp[i];
st=poz;
dr=i;
}
}
fout << rez << " " << st << " " << dr;
return 0;
}
