Pagini recente » Cod sursa (job #2930920) | Cod sursa (job #1743839) | Cod sursa (job #280258) | Cod sursa (job #777679) | Cod sursa (job #586071)
Cod sursa(job #586071)
#include<stdio.h>
#include<queue>
using namespace std;
typedef pair<long long,int> PLI;
//typedef pair<int,PLI> PIP;
//priority_queue<PIP,vector<PIP>,greater<PIP> > Ao,B0;
priority_queue<PLI,vector<PLI>,greater<PLI> > A,Bo;
priority_queue<int,vector<int>,greater<int> > B;
/*struct rezolvafd{
long long timp;
int dur;
}*/
long long nra[100100],nrb[100100],timp;
int N,Na,Nb,T;
int main(){
freopen("fabrica.in","r",stdin);
freopen("fabrica.out","w",stdout);
int i,j,x,y;
scanf("%d%d%d",&N,&Na,&Nb);
for(i=0;i<Na;++i){
scanf("%d",&x);
A.push(PLI(x,x));
}
for(i=0;i<Nb;++i){
scanf("%d",&x);
Bo.push(PLI(x,x));
}
for(i=1;i<=N;++i){
x=A.top().first;
y=A.top().second;
A.pop();
nra[i]=x;
A.push(PLI((long long)(x+y),y));
}
printf("%lld ",nra[N]);
fflush(stdout);
j=1;
for(i=1;i<=N;++i){
x=Bo.top().first;
y=Bo.top().second;
Bo.pop();
nrb[N-i+1]=x;
Bo.push(PLI((long long)(x+y),y));
}
timp=0;
for(i=1;i<=N;++i){
if(nra[i]+nrb[i]>timp)
timp=nra[i]+nrb[i];
}
/*for(i=1;i<=N;++i){
if(timp<nra[i])
timp=nra[i];
if(B.empty()){
x=Bo.top().first;
y=Bo.top().second;
if(timp<x)
timp=x;
B.push(y);
}
x=B.top();
B.pop();
nrb[i]=timp+x;
Bo.push(PLI((long long)(timp+x),x));
}*/
printf("%lld\n",timp);
fclose(stdin);
fclose(stdout);
return 0;
}