Pagini recente » Cod sursa (job #129119) | Cod sursa (job #2185750) | Cod sursa (job #2457133) | Cod sursa (job #828409) | Cod sursa (job #585900)
Cod sursa(job #585900)
#include <fstream>
#include <algorithm>
#include <queue>
using namespace std;
const unsigned maxn = 50009;
priority_queue <pair<unsigned,unsigned>, vector<pair<unsigned,unsigned> >, greater<pair<unsigned,unsigned> > >q, qb;
unsigned a [ maxn ], b [ maxn ];
unsigned tf [ maxn ];
int main (){
int n, na, nb, i;
ifstream f ( "fabrica.in" );
f >> n >> na >> nb;
unsigned int maxb ( 0 ), ti, maxs ( 0 );
for ( i = 0; i < na; ++ i ) {
f >> ti;
q.push(make_pair(ti, i ) );
a [ i ] = ti;
}
for ( i = 0; i < nb; ++ i ) {
f >> ti;
qb.push(make_pair(ti, i ) );
b [ i ] = ti;
}
pair<unsigned,unsigned> v, v2;
for ( i = 0; i < n; ++ i ){
v = q.top();
q.pop();
maxb = max ( maxb, v.first );
tf [ i ] = v.first;
v.first += a [ v.second ];
q.push(v);
}
sort ( tf, tf + n );
for ( i = 0; i < n; ++ i ) {
v = qb.top();
qb.pop();
v.first = v.first - b [ v.second ] < tf [ i ] ? tf [ i ] + b [ v.second ] : v.first;
maxs = max ( maxs, v.first );
v.first += b [ v.second ];
qb.push(v);
}
ofstream g("fabrica.out");
g << maxb << " " << maxs << endl;
g.close();
return 0;
}