Pagini recente » Cod sursa (job #1516416) | Cod sursa (job #737074) | Cod sursa (job #2184014) | Cod sursa (job #1247945) | Cod sursa (job #585614)
Cod sursa(job #585614)
#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
set<per> a,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=top.x;
a.insert(make_pair(top.x+ta[top.y],top.y));
ttb=tta+ta[top.y];
top=*b.begin();
b.erase(b.begin());
b.insert(make_pair(ttb+tb[top.y],top.y));
for(int i=2; i<=n; ++i) {
if(ra) {
top=*a.begin();
a.erase(a.begin());
--ra;
tta=top.x;
a.insert(make_pair(top.x+ta[top.y],top.y));
}
if(0==ra && 0==ok) {
g<<tta<<' ';
ok=1;
}
top=*b.begin();
b.erase(b.begin());
ttb=top.x;
b.insert(make_pair(ttb+tb[top.y],top.y));
}
top=*b.begin();
g<<ttb<<'\n';
return 0;
}