Pagini recente » Cod sursa (job #1797801) | Cod sursa (job #2265707) | Cod sursa (job #2908630) | Cod sursa (job #1455453) | Cod sursa (job #2540822)
#pragma GCC optimize("Ofast")
/*
/\__/\
( • - •)
/ >🍪
why hack me, better eat a cookie
*/
#include<bits/stdc++.h>
#define Plan_B() cout<<"HESOYAM"
#define all(s) s.begin(),s.end()
#define rc(x) return cout<<x,0
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
typedef long long ll;
const ll nmax=1e6;
const ll mod=700001;
const ll inf=2e9+3;
using namespace std;
#define DEBUG
int main()
{
#ifdef DEBUG
freopen("deque.in","r",stdin);
freopen("deque.out","w",stdout);
#endif
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
int n,k;
cin>>n>>k;
set<int>s;
queue<int>q;
ll ans=0;
for(int i=1;i<=n;i++)
{
int x;
cin>>x;
s.insert(x);
q.push(x);
if(i>k)
{
s.erase(q.front());
q.pop();
}
if(i>=k) ans+=ll((*s.begin()));
}
cout<<ans;
}