Cod sursa(job #763597)
| Utilizator | Data | 2 iulie 2012 17:35:04 | |
|---|---|---|---|
| Problema | Subsecventa de suma maxima | Scor | 95 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.63 kb |
#include <cstdio>
#include <algorithm>
using namespace std;
int n;
int main(){
freopen("ssm.in","r",stdin);
freopen("ssm.out","w",stdout);
scanf("%d",&n);
int p,u,bst,p1,bst1,x;
scanf("%d",&bst);
p = u = p1 = 1; bst1 = bst;
for(int i=2;i<=n;i++)
{
scanf("%d",&x);
if(x >= bst1 + x)
{
bst1 = x;
p1 = i;
} else bst1 += x;
if(bst1 > bst)
{
bst = bst1;
p = p1;
u = i;
}
}
printf("%d %d %d\n",bst,p,u);
return 0;
}
