Pagini recente » Cod sursa (job #2500883) | Cod sursa (job #192274) | Cod sursa (job #1570351) | Cod sursa (job #1215432) | Cod sursa (job #585946)
Cod sursa(job #585946)
#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);
B.push(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){
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",nrb[N]);
fclose(stdin);
fclose(stdout);
return 0;
}