Cod sursa(job #2346759)

Utilizator stefantagaTaga Stefan stefantaga Data 18 februarie 2019 08:26:07
Problema Fabrica Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.12 kb
#include <fstream>
#include <queue>
using namespace std;
ifstream f("fabrica.in");
ofstream g("fabrica.out");
priority_queue <pair <int,int>,vector <pair <int,int >  > , greater <pair <int,int > >    > h;
int n,nra,nrb;
int copie[100005],v[100005],reza[100005],i,poz,rezb[100005],maxim;
int main()
{
    f>>n>>nra>>nrb;
    for (i=1;i<=nra;i++)
    {
        f>>v[i];
        copie[i]=v[i];
        h.push({v[i],i});
    }
    for (i=1;i<=n;i++)
    {
        reza[i]=h.top().first;
        poz=h.top().second;
        v[h.top().second]+=copie[h.top().second];
        h.pop();
        h.push({v[poz],poz});
    }
    g<<reza[n];
    while (!h.empty())
    {
        h.pop();
    }
   for (i=1;i<=nrb;i++)
    {
        f>>v[i];
        copie[i]=v[i];
        h.push({v[i],i});
    }
    for (i=1;i<=n;i++)
    {
        rezb[i]=h.top().first;
        poz=h.top().second;
        v[h.top().second]+=copie[h.top().second];
        h.pop();
        h.push({v[poz],poz});
    }
    for (i=1;i<=n;i++)
    {
        maxim=max(maxim,reza[i]+rezb[n-i+1]);
    }
    g<<" "<<maxim;
    return 0;
}