Cod sursa(job #2329817)

Utilizator hhhhhhhAndrei Boaca hhhhhhh Data 27 ianuarie 2019 15:10:30
Problema Deque Scor 20
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.77 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("deque.in");
ofstream fout("deque.out");
long long n,k,v[5000001],i,suma,minim,x,j;
int main()
{
    fin>>n>>k;
    minim=99999999999999999;
    for(i=1;i<=k;i++)
    {
        fin>>v[i];
        if(v[i]<minim)
            minim=v[i];
    }
    suma=minim;
    for(i=1;i<=n-k;i++)
    {
        fin>>x;
        if(minim==v[1])
        {
            minim=99999999999;
            for(j=2;j<=k;j++)
                if(v[j]<minim)
                    minim=v[j];
            if(x<minim)
                minim=x;
        }
        else
            minim=min(minim,x);
        for(j=2;j<=k;j++)
            v[j-1]=v[j];
        v[k]=x;
        suma+=minim;
    }
    fout<<suma;
    return 0;
}