Cod sursa(job #1527245)

Utilizator CraiuAndrei Craiu Craiu Data 17 noiembrie 2015 22:31:57
Problema Secventa 2 Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <bits/stdc++.h>
#define nmax 50005

using namespace std;

ifstream fin("secv2.in");
ofstream fout("secv2.out");

int n, k;
int v[nmax], a[nmax];

int main()
{
    int i, st, dr;
    long long smax;
    fin >> n >> k;
    smax = -999999999999;
    for(i = 1; i <= n; i++)
        fin >> v[i];
    for(i = 1; i <= n; i++)
    {
        a[i] = a[i - 1] + v[i];
        if(a[i] > smax)
        {
            smax = a[i];
            dr = i;
        }
    }
    for(i = 1; i <= n; i++)
        a[i] = 0;
    smax = -999999999999;
    for(i = dr; i >= 1; i--)
    {
        a[i] = a[i + 1] + v[i];
        if(a[i] > smax)
        {
            smax = a[i];
            st = i;
        }
    }
    fout<<st<<" "<<dr<<" "<<smax;
    //fout << st  << " "<< dr<< " " << smax;
    fout.close();
    return 0;
}