Cod sursa(job #901108)

Utilizator RaduDoStochitoiu Radu RaduDo Data 1 martie 2013 00:28:22
Problema Subsecventa de suma maxima Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.72 kb
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<bitset>
#define INF 0x3f3f3f3f
#define mp make_pair
#define pb push_back
#define maxn 6000010
using namespace std;
int best[maxn],n,dr,st,st_f,i,maxi;

int main()
{
    freopen("ssm.in","r",stdin);
    freopen("ssm.out","w",stdout);
    scanf("%d%d",&n,&best[1]);
    maxi=best[1]; st=dr=1;
    for(i=2; i<=n; ++i)
    {
        scanf("%d",&best[i]);
        if(best[i]<=best[i-1]+best[i])
            best[i]=best[i-1]+best[i];
        else
            st=i;
        if(maxi<best[i])
            maxi=best[i],dr=i,st_f=st;
    }
    printf("%d %d %d\n",maxi,st_f,dr);
    return 0;
}