求助今晚ABC E题,为啥RE
  • 板块灌水区
  • 楼主zjc2008
  • 当前回复3
  • 已保存回复3
  • 发布时间2022/12/10 21:41
  • 上次更新2023/10/26 23:51:57
查看原帖
求助今晚ABC E题,为啥RE
376103
zjc2008楼主2022/12/10 21:41

思路就是优先队列做

代码如下

#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;
}
2022/12/10 21:41
加载中...