Cod sursa(job #884283)

Utilizator miron_dorin95Miron Dorin miron_dorin95 Data 20 februarie 2013 20:36:24
Problema Subsecventa de suma maxima Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.59 kb
#include <iostream>
#include <fstream>
using namespace std;
int n,v[6000001],bst[6000001],mx;
ifstream f("ssm.in");
ofstream g("ssm.out");
void citire()
{
    int i;
    f>>n;
    for(i=1;i<=n;i++)
        f>>v[i];
}
int main()
{
    int i,s=0;
    citire();
    bst[1]=v[1];
    for(i=2;i<=n;i++)
    {
        bst[i]=v[i];
        if(bst[i]<bst[i-1]+v[i])
            bst[i]=bst[i-1]+v[i];
        if(mx<bst[i])
            mx=i;
    }
    g<<bst[mx]<<endl;
    i=mx;
    while(bst[i]!=v[i])
    {
        i--;
        s++;
    }
    g<<mx-s<<" "<<mx;
    return 0;
}