帮个忙谢谢
查看原帖
帮个忙谢谢
779733
lgshuang楼主2023/5/21 11:31

帮个忙,WA了。。。QwQ

#include <bits/stdc++.h>
#define N 114514 
using namespace std;
int read(){
	int res=0,w=1;
	char c=getchar();
	if(c=='-'){ w=-1; c=getchar(); }
	while(c>='0' && c<='9'){ res=res*10+c-'0'; c=getchar(); }
	return res*w;
}
int n;
int a[N],s[N],max1,max2,sum;
struct data1{
	int id;
	bool operator<(const data1 b)const{
		return a[id]<a[b.id];
	}
};
struct data2{
	int id;
	bool operator<(const data2 b)const{
		return a[id]+2*s[id]<a[b.id]+2*s[b.id];
	}
};
priority_queue <data1> q1;
priority_queue <data2> q2;
int main(){
	n=read();
	for(int i=1; i<=n; i++){
		s[i]=read();
	} 
	for(int i=1; i<=n; i++){
		a[i]=read();
	}
	for(int i=1; i<=n; i++){
		q2.push(data2{i});
	}
	int now=0;
	for(int k=1; k<=n; k++){
		if(!q1.empty()){
			max1=a[q1.top().id];
		}
		else{
			max1=0;
		}
		while(!q2.empty() and q2.top().id<now){
			q2.pop();
		}
		if(!q2.empty()){
			max2=a[q2.top().id]+2*(s[q2.top().id]-s[now]);
		}
		else{
			max2=0;
		}
		if(max1>=max2) {
			sum+=max1;
			q1.pop();
		}
		else{
			sum+=max2;	
			for(int j=now+1; j<q2.top().id-1; j++){
				q1.push(data1{j});
			}
			q2.pop();
			now=q2.top().id;
		}		
		cout<<sum<<endl;
	}
	return 0;
}
2023/5/21 11:31
加载中...