Cod sursa(job #585744)

Utilizator MciprianMMciprianM MciprianM Data 30 aprilie 2011 11:35:22
Problema Fabrica Scor 20
Compilator cpp Status done
Runda Algoritmiada 2011, Runda Finală, Open Marime 0.73 kb
#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;
int a [ maxn ];


int main (){
    int n, na, nb, i;
    ifstream f ( "fabrica.in" );
    f >> n >> na >> nb;
    unsigned int maxb ( 0 ), ti;
    for ( i = 0; i < na; ++ i ) {
        f >> ti;
        q.push(make_pair(ti, i ) );
        a [ i ] = ti;
    }
    pair<unsigned,unsigned> v;
    for ( i = 0; i < n; ++ i ){
        v = q.top();
        q.pop();
        maxb = max ( maxb, v.first );
        v.first += a [ v.second ];
        q.push(v);
    }
    ofstream g("fabrica.out");
    g << maxb << " 0" << endl;
    g.close();
    return 0;
}