Pagini recente » Cod sursa (job #1313492) | Cod sursa (job #3215113) | Cod sursa (job #3240722) | Cod sursa (job #3138902) | Cod sursa (job #585809)
Cod sursa(job #585809)
#include <fstream>
#include <queue>
using namespace std;
const int maxn = 50009;
priority_queue <pair<unsigned,unsigned>, vector<pair<unsigned,unsigned> >, greater<pair<unsigned,unsigned> > >q, qb;
int a [ maxn ], b [ maxn ];
int main (){
int n, na, nb, i;
ifstream f ( "fabrica.in" );
f >> n >> na >> nb;
unsigned int maxb ( 0 ), ti, maxs ( 0 ), delay ( 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();
v2 = qb.top();
q.pop();
qb.pop();
maxb = max ( maxb, v.first );
v2.first += b [ v.second ];
delay += max ( 0u, v2.first - v.first - b [ v2.second ] );
v.first += a [ v.second ];
q.push(v);
maxs = max ( maxs, v.first + delay );
qb.push(v);
}
ofstream g("fabrica.out");
g << maxb << " " << maxs << endl;
g.close();
return 0;
}