样例过不了,求调
  • 板块灌水区
  • 楼主PUTONGDEYITIREN
  • 当前回复3
  • 已保存回复3
  • 发布时间2024/11/3 17:04
  • 上次更新2024/11/3 20:32:31
查看原帖
样例过不了,求调
1003873
PUTONGDEYITIREN楼主2024/11/3 17:04

题目传送门

#include<bits/stdc++.h>
using namespace std;
long long n,m,ans,b[250005],l;
struct node{
	long long p,id,l,r;
	bool operator<(node b)const{
		return p<b.p;
	}
}a[250005];
priority_queue<node> q;
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++) cin>>a[i].p,a[i].id=i;
	if(m>n/2){
		cout<<"Error!";
		return 0;
	}
	for(int i=1;i<=n;i++){
		a[i].l=(i+n-2)%n+1;
		a[i].r=(i+n)%n+1;
		//cout<<a[i].l<<" "<<a[i].r<<endl;
		q.push(a[i]);
	} 
	l=q.size();
	while(m){
		while(b[q.top().id]) q.pop();
		node t=q.top();
		q.pop();
		ans+=t.p;
		t.p=a[t.l].p+a[t.r].p-t.p;
		b[a[t.l].id]=1;
		b[a[t.r].id]=1;
		a[a[t.l].l].r=t.id;
		a[a[t.r].r].l=t.id;
		t.l=a[t.l].l;
		t.r=a[t.r].r;
		a[t.id]=t;
		q.push(t);
		m--;
	}
	cout<<ans;
return 0;
}
2024/11/3 17:04
加载中...