Pagini recente » Cod sursa (job #2472068) | Cod sursa (job #127751) | Cod sursa (job #1684465) | Cod sursa (job #1353006) | Cod sursa (job #2401945)
#include <cstdio>
#include <queue>
#define DIM 100010
using namespace std;
priority_queue <pair <int,int> > h,h2,h3;
int ta[DIM],tb[DIM];
int main()
{
FILE *fin=fopen ("fabrica.in","r");
FILE *fout=fopen ("fabrica.out","w");
int n,na,nb,i,maxi,ending,poz,luat,maxi2,timp;
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]);
h2.push(make_pair(-tb[i],i)); /// in h2 e tot ce e disponibil ACUM
}
/// punctul A :
maxi=0;
maxi2=0;
luat=0;
while (luat<n){
luat ++;
ending= -h.top().first;
maxi=max(maxi,ending);
/// procesul A asta se termina la ending
poz= h.top().second;
h.pop();
h.push(make_pair(-ending - ta[poz],poz));
while (!h3.empty() && h3.top().first<=ending ){
timp = -h3.top().first;
poz = h3.top().second;
h2.push(make_pair(-tb[poz],poz));
h3.pop();
}
maxi2=max(maxi2,ending + (-h2.top().first)); /// il bagi in proces B care dureaza
/// cat mai putin
timp= -h2.top().first;
poz= h2.top().second;
h2.pop(); /// nu mai e disponibil, o sa fie iar disponibil la timpul end+timp
timp+=ending;
h3.push(make_pair(-timp,poz));
}
fprintf (fout,"%d %d",maxi,maxi2);
return 0;
}