Pagini recente » Cod sursa (job #19937) | Cod sursa (job #2029463) | Cod sursa (job #1138079) | Cod sursa (job #86738) | Cod sursa (job #2402230)
#include <cstdio>
#include <queue>
#include <algorithm>
#define DIM 100010
using namespace std;
priority_queue <pair <int,int> > h;
int ta[DIM],tb[DIM];
int v[DIM],w[DIM];
int main()
{
FILE *fin=fopen ("fabrica.in","r");
FILE *fout=fopen ("fabrica.out","w");
int n,na,nb,i,maxi,ending,poz,luat;
fscanf (fin,"%d%d%d",&n,&na,&nb);
for (i=1;i<=na;i++){
fscanf (fin,"%d",&ta[i]);
h.push(make_pair(-ta[i],i));
}
for (i=1;i<=nb;i++){
fscanf (fin,"%d",&tb[i]);
}
/// punctul A :
maxi=0;
luat=0;
while (luat<n){
luat ++;
ending= -h.top().first;
maxi=max(maxi,ending);
v[luat]=ending;
poz= h.top().second;
h.pop();
h.push(make_pair(-ending - ta[poz],poz));
}
fprintf (fout,"%d ",maxi);
/// gata pct A
while (!h.empty())
h.pop();
for (i=1;i<=nb;i++){
h.push(make_pair(-tb[i],i)); /// in h2 e tot ce e disponibil ACUM
}
luat=0;
while (luat<n){
luat ++;
ending= -h.top().first;
w[luat]=ending;
poz= h.top().second;
h.pop();
h.push(make_pair(-ending - tb[poz],poz));
}
sort (v+1,v+n+1);
sort (w+1,w+n+1);
maxi=0;
for (i=1;i<=n;i++)
maxi=max(maxi,v[i] + w[n-i+1]);
fprintf (fout,"%d ",maxi);
return 0;
}