Cod sursa(job #2112665)

Utilizator stefdascalescuStefan Dascalescu stefdascalescu Data 23 ianuarie 2018 19:08:06
Problema Fabrica Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.2 kb
/// #bettercoderthanshebeautiful
#include<bits/stdc++.h>
using namespace std;
ifstream f("fabrica.in");
ofstream g("fabrica.out");
int n,a,b;
int qtime[100002];
struct proc
{
    int tfree,per;
};
proc v[50002];
struct cmp
{
    bool operator()(int a, int b)
    {
        if(v[a].tfree==v[b].tfree)
            return v[a].per>v[b].per;
        return v[a].tfree>v[a].tfree;
    }
};
priority_queue<int,vector<int>,cmp>q;
int main()
{
    f>>n>>a>>b;
    for(int i=1;i<=a;++i)
    {
        f>>v[i].per;
        q.push(i);
    }
    for(int i=1;i<=n;++i)
    {
        qtime[i]=v[q.top()].tfree+v[q.top()].per;
        v[q.top()].tfree+=v[q.top()].per;
        int x=q.top();
        q.pop();
        q.push(x);
    }
    sort(qtime+1,qtime+n+1);
    g<<qtime[n]<<" ";
    while(!q.empty())
        q.pop();
    for(int i=1;i<=b;++i)
    {
        f>>v[i].per;
        v[i].tfree=0;
        q.push(i);
    }
    int tmax=0;
    for(int i=n;i>=1;--i)
    {
        tmax=max(tmax,qtime[i]+v[q.top()].tfree+v[q.top()].per);
        v[q.top()].tfree+=v[q.top()].per;
        int x=q.top();
        q.pop();
        q.push(x);
    }
    g<<tmax<<'\n';
    return 0;
}