马蜂丑,请看看吧qwq
#include<stdio.h>
#include<queue>
using namespace std;
#define N 1000009
#define ll long long
ll a[N];
deque < ll > q;
inline ll max(ll a, ll b) {return a > b ? a : b;}
signed main()
{
int k, n;
scanf("%d%d", &k, &n);
unsigned ll sum = 0;
for (int i = 1;i <= n;i ++)
{
scanf("%lld", &a[i]);
while (!q.empty() && a[q.back()] < a[i])
q.pop_back();
while (!q.empty() && q.front() <= i - k)
q.pop_front();
q.push_back(i);
if (i >= k)
{
if (a[q.front()] > 0)
sum += a[q.front()] --;
printf("%llu ", sum);
}
}
return 0;
}