Cod sursa(job #3004787)
| Utilizator | Data | 16 martie 2023 16:43:26 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.57 kb |
#include <fstream>
#include <cmath>
#include <queue>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int n,st,stmax,drmax;
long long s,maxim=-10000000000000;
int main()
{
fin >> n;
st=1;
for(int i=1;i<=n;i++)
{
int x;
fin >> x;
s=s+x;
if(maxim<s)
{
maxim=s;
stmax=st;
drmax=i;
}
if(s<0)
{
s=0;
st=i+1;
}
}
fout << maxim << " " << stmax << " " << drmax;
return 0;
}
