思路就是优先队列做
代码如下
#include<bits/stdc++.h>
using namespace std;
//#define int long long
int n , m , k , ans;
struct node{
int x , id;
}a[200005];
typedef pair<int,int>pii;
priority_queue <pii> q1;
priority_queue<pii,vector<pii>,greater<pii> >q2;
signed main()
{
cin >> n >> m >> k;
for(int i = 1;i <= n;i++)
{
cin >> a[i].x;
a[i].id = i;
}
for(int i = 1;i <= n;i++)
{
cout << i << ' ';
// cin >> a[i].x;
int x = a[i].x;
// a[i].id = i;
if(q1.empty() || q1.size() < k)q1.push(make_pair(x , i)) , ans += x;
else if(i <= m)
{
if(x < q1.top().first)
{
ans -= q1.top().first;
q1.pop();
ans += x;
q1.push(make_pair(x , i));
}
else q2.push(make_pair(x , i));
}
if(i > m)
{
ans -= a[i - m].x;
while(q2.top().second <= i - m && !q2.empty())q2.pop();
if(x < q2.top().first)
{
ans += x;
q1.push(make_pair(x , i));
}
else
{
ans += q2.top().first;
q2.pop();
}
cout << ans << ' ';
}
}
return 0;
}