Cod sursa(job #2494106)

Utilizator Andrei_CotorAndrei Cotor Andrei_Cotor Data 17 noiembrie 2019 12:43:15
Problema Fabrica Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.1 kb
#include<fstream>
#include<queue>

using namespace std;

ifstream fi("fabrica.in");
ofstream fo("fabrica.out");

int A[50005],B[50005],TimeA[100005],TimeB[100005];

int main()
{
    int n,m1,m2;
    fi>>n>>m1>>m2;

    priority_queue<pair<int,int> > Pq;
    for(int i=1; i<=m1; i++)
    {
        fi>>A[i];
        Pq.push({-A[i],i});
    }

    for(int i=1; i<=m2; i++)
        fi>>B[i];

    for(int i=1; i<=n; i++)
    {
        int time=-Pq.top().first;
        int ind=Pq.top().second;
        Pq.pop();

        TimeA[i]=time;

        time+=A[ind];
        Pq.push({-time,ind});
    }

    while(!Pq.empty())
        Pq.pop();

    for(int i=1; i<=m2; i++)
        Pq.push({-B[i],i});

    for(int i=1; i<=n; i++)
    {
        int time=-Pq.top().first;
        int ind=Pq.top().second;
        Pq.pop();

        TimeB[i]=time;

        time+=B[ind];
        Pq.push({-time,ind});
    }

    int rez=0;
    for(int i=1; i<=n; i++)
        rez=max(rez,TimeA[i]+TimeB[n-i+1]);

    fo<<TimeA[n]<<" "<<rez<<"\n";
    fi.close();
    fo.close();
    return 0;
}