Pagini recente » Cod sursa (job #1522428) | Cod sursa (job #2919324) | Cod sursa (job #1529381) | Cod sursa (job #1271360) | Cod sursa (job #588705)
Cod sursa(job #588705)
#include <iostream>
#include <fstream>
#include <set>
#define DNR 50005
#define x first
#define y second
using namespace std;
typedef pair<int, int> per;//timp,proc
struct classcomp {
bool operator() (const per& lhs, const per& rhs) const
{return lhs>rhs;}
};
multiset<per> a;
multiset<per,classcomp> b;
int n,na,nb,ta[DNR],tb[DNR],ra,rb,tta,ttb;
int main()
{
ifstream f("fabrica.in");
ofstream g("fabrica.out");
f>>n>>na>>nb;
ra=rb=n;
for(int i=1; i<=na; ++i) {
f>>ta[i];
a.insert(make_pair(ta[i],i));
}
for(int i=1; i<=nb; ++i) {
f>>tb[i];
b.insert(make_pair(tb[i],i));
}
per top;
bool ok=0;
top=*a.begin();
a.erase(a.begin());
--ra;
tta=max(tta,top.x);
a.insert(make_pair(top.x+ta[top.y],top.y));
ttb=max(ttb,tta);
top=*b.begin();
b.erase(b.begin());
b.insert(make_pair(top.x+tb[top.y],top.y));
int aux;
for(int i=2; i<=n; ++i) {
top=*a.begin();
a.erase(a.begin());
--ra;
tta=max(tta,top.x);
a.insert(make_pair(top.x+ta[top.y],top.y));
aux=top.x;
top=*b.begin();
b.erase(b.begin());
ttb=max(ttb,aux+top.x);
b.insert(make_pair(top.x+tb[top.y],top.y));
}
top=*b.begin();
g<<tta<<' '<<ttb+tb[top.y]<<'\n';
return 0;
}