Cod sursa(job #2353210)

Utilizator Cristian25Cristian Stanciu Cristian25 Data 23 februarie 2019 23:33:38
Problema Deque Scor 60
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.7 kb
#include <fstream>
#include <vector>
#include <set>
#define pb push_back

using namespace std;

ifstream in("deque.in");
ofstream out("deque.out");

typedef long long llong;

vector<llong> v;
multiset<llong> my_set;

llong N, K, sum, cont;

int main()
{
    in >> N >> K;
    for(llong i = 1; i <= K; ++i)
    {
        llong val;
        in >> val;
        my_set.insert(val);
        v.pb(val);
    }
    for(llong i = 1; i <= N - K; ++i)
    {
        sum += *my_set.begin();
        my_set.erase(my_set.find(v[cont]));
        llong val;
        in >> val;
        my_set.insert(val);
        v.pb(val);
        ++cont;
    }
    out << sum + *my_set.begin();
    return 0;
}