Cod sursa(job #2402229)

Utilizator Ruxandra985Nanu Ruxandra Laura Ruxandra985 Data 10 aprilie 2019 14:56:46
Problema Fabrica Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.38 kb
#include <cstdio>
#include <queue>
#include <algorithm>
#define DIM 100010
using namespace std;
priority_queue <pair <int,int> > h;
int ta[DIM],tb[DIM];
int v[DIM],w[DIM];
int main()
{
    FILE *fin=fopen ("fabrica.in","r");
    FILE *fout=fopen ("fabrica.out","w");
    int n,na,nb,i,maxi,ending,poz,luat;
    fscanf (fin,"%d%d%d",&n,&na,&nb);
    for (i=1;i<=na;i++){
        fscanf (fin,"%d",&ta[i]);
        h.push(make_pair(-ta[i],i));
    }
    for (i=1;i<=nb;i++){
        fscanf (fin,"%d",&tb[i]);
    }
    /// punctul A :
    maxi=0;
    luat=0;
    while (luat<n){
        luat ++;
        ending= -h.top().first;
        maxi=max(maxi,ending);
        v[luat]=ending;
        poz= h.top().second;
        h.pop();
        h.push(make_pair(-ending - ta[poz],poz));
    }
    fprintf (fout,"%d ",maxi);

    /// gata pct A
    while (!h.empty())
        h.pop();
    for (i=1;i<=nb;i++){
        h.push(make_pair(-tb[i],i)); /// in h2 e tot ce e disponibil ACUM
    }
    luat=0;
    while (luat<n){
        luat ++;
        ending= -h.top().first;
        w[luat]=ending;
        poz= h.top().second;
        h.pop();
        h.push(make_pair(-ending - ta[poz],poz));
    }
    sort (v+1,v+n+1);
    sort (w+1,w+n+1);
    maxi=0;
    for (i=1;i<=n;i++)
        maxi=max(maxi,v[i] + w[n-i+1]);
    fprintf (fout,"%d ",maxi);
    return 0;
}