Cod sursa(job #2041581)
| Utilizator | Data | 17 octombrie 2017 17:12:29 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 80 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.55 kb |
#include<bits/stdc++.h>
#define MAX 6000001
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
long long a[MAX],n;
int main()
{
long long smax,s,p,x,y;
fin>>n;
int i;
for(i=1;i<=n;i++)
fin>>a[i];
smax = s = a[1];
if (s < 0) { s = 0; p=2;}
for (i=2; i<=n; i++)
{
s += a[i];
if (smax < s)
{
smax = s;
x=p;
y=i;
}
if (s < 0) {s = 0; p=i+1;}
}
fout << smax<<" "<<x<<" "<<y;
return 0;
}
