1. 程式人生 > >易水決[堆][貪心]

易水決[堆][貪心]

 


分析 

(https://blog.csdn.net/dreaming__ldx/article/details/83447671)


#include<bits/stdc++.h>
#define N 1000005
#define LL long long
using namespace std;
LL l,n,m,a[N],b[N],p[N],q[N],ans;
struct Node{
	LL pos,val;
	bool operator < (const Node &a) const{
		return a.val<val;
	}
};
priority_queue<Node> A,B;
LL read(){
	LL cnt=0; char ch=0;
	while(!isdigit(ch)) ch=getchar();
	while(isdigit(ch))cnt=cnt*10+(ch-'0'),ch=getchar();
	return cnt;
}
int main(){;
	l=read(),n=read(),m=read();
	for(int i=1;i<=n;i++) a[i]=read(),A.push(Node{i,a[i]});
	for(int i=1;i<=m;i++) b[i]=read(),B.push(Node{i,b[i]});
	for(int i=1;i<=l;i++){
		Node x=A.top();
		p[i]=x.val;
		A.pop(),A.push(Node{x.pos,x.val+a[x.pos]});
		Node y=B.top();
		q[i]=y.val;
		B.pop(),B.push(Node{y.pos,y.val+b[y.pos]});
	}
	for(int i=1;i<=l;i++) ans=max(ans,p[i]+q[l-i+1]);
	printf("%lld\n",ans); return 0;
}