Cod sursa(job #2266215)

Utilizator victorv88Veltan Victor victorv88 Data 22 octombrie 2018 14:54:20
Problema Secventa 2 Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.02 kb
#include <iostream>
#include <fstream>
#include <deque>
#include <cstring>

using namespace std;

ifstream f("secv2.in");
ofstream g("secv2.out");

int index_max_inceput, index_max_final, index_inceput, index_final, vect[50005],n, k,s,smax,indexx;

int main() {
    f >> n >> k;
    index_inceput=1;
    index_final=k;
    index_max_final=k;
    index_max_inceput=1;
    for (int i=1; i<=k; i++)
    {
        f >> vect[i];
        s+=vect[i];

    }
    smax=s;
    for (int i=k+1; i<=n; i++)
    {
        f >> vect[i];
        s+=vect[i];
        index_final++;
        int aux=s;
        for ( indexx=index_inceput; indexx<i-k+1; indexx++)
        {
            aux-=vect[indexx];
            if (aux>s)
            {
                index_inceput=indexx+1;
                s=aux;
            }
        }
        if (s>smax)
        {
            smax=s;
            index_max_inceput=index_inceput;
            index_max_final=index_final;
        }
    }
    g << index_max_inceput <<' ' << index_max_final <<' ' <<smax;
    return 0;
}