Cod sursa(job #585900)

Utilizator MciprianMMciprianM MciprianM Data 30 aprilie 2011 12:33:30
Problema Fabrica Scor 12
Compilator cpp Status done
Runda Algoritmiada 2011, Runda Finală, Open Marime 1.24 kb
#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;
}