我用的优先队列,没有用pair,想法是,判断木板向右移动时,挪开的那个数字是否为队列中的队首,如果是,就把队首弹出。
但是只有10分,求助!
#include<bits/stdc++.h>
#define ll long long
const ll MAXN = 2e7 + 10;
using namespace std;
ll n, k;
ll a[MAXN];
priority_queue<ll, vector<ll>, less<ll> > q;
int main()
{
cin >> n >> k;
for(int i = 1; i <= n; i ++)
{
cin >> a[i];
if(i <= k) q.push(a[i]);
}
for(int i = 1; i <= n - k + 1; i ++)
{
cout << q.top();
if(i != n - k + 1) cout << endl;
if(q.top() == a[i]) q.pop();
q.push(a[i + k]);
}
return 0;
}