Cod sursa(job #609185)

Utilizator a_h1926Heidelbacher Andrei a_h1926 Data 19 august 2011 20:19:26
Problema Fabrica Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.38 kb
#include <iostream>

#define NMax 100005
#define D 0
#define P1 1
#define P2 2
#define PMax 3
#define Inf 100000000

using namespace std;

int NH[PMax], TimeA[NMax], TimeB[NMax], V[PMax][NMax];
int Heap[PMax][NMax], Poz[PMax][NMax];
int S1, S2;

inline int Max (int a, int b)
{
    if (a>b)
    {
        return a;
    }
    return b;
}

inline void Swap (int X, int Y, int H)
{
    int Aux=Poz[H][Heap[H][X]];
    Poz[H][Heap[H][X]]=Poz[H][Heap[H][Y]];
    Poz[H][Heap[H][Y]]=Aux;
    Aux=Heap[H][X];
    Heap[H][X]=Heap[H][Y];
    Heap[H][Y]=Aux;
}

void Percolate (int X, int H)
{
    int Father=X>>1;
    if (Father>0 and V[H][Heap[H][X]]<V[H][Heap[H][Father]])
    {
        Swap (X, Father, H);
        Percolate (Father, H);
    }
}

void Sift (int X, int H)
{
    int Son=X<<1;
    if (Son+1<=NH[H] and V[H][Heap[H][Son+1]]<V[H][Heap[H][Son]])
    {
        ++Son;
    }
    if (Son<=NH[H] and V[H][Heap[H][Son]]<V[H][Heap[H][X]])
    {
        Swap (X, Son, H);
        Sift (Son, H);
    }
}

void Read ()
{
    freopen ("fabrica.in", "r", stdin);
    scanf ("%d %d %d", &NH[D], &NH[P1], &NH[P2]);
    for (int i=1; i<=NH[P1]; ++i)
    {
        Heap[P1][i]=Poz[P1][i]=i;
        scanf ("%d", &TimeA[i]);
    }
    for (int i=1; i<=NH[P2]; ++i)
    {
        Heap[P2][i]=Poz[P1][i]=i;
        scanf ("%d", &TimeB[i]);
    }
    for (int i=1; i<=NH[D]; ++i)
    {
        Heap[D][i]=Poz[D][i]=i;
    }
}

void ProcessA ()
{
    for (int i=1; i<=NH[D]; ++i)
    {
        int Dose=Heap[D][1];
        int Processor=Heap[P1][1];
        V[P1][Processor]+=TimeA[Processor];
        Sift (1, P1);
        V[D][Dose]+=TimeA[Processor];
        Sift (1, D);
    }
    for (int i=1; i<=NH[P1]; ++i)
    {
        S1=Max (S1, V[P1][i]);
    }
}

void ProcessB ()
{
    for (int i=1; i<=NH[D]; ++i)
    {
        int Dose=Heap[D][1];
        int Processor=Heap[P2][1];
        V[P2][Processor]=Max (V[P2][Processor], V[D][Dose]);
        V[P2][Processor]+=TimeB[Processor];
        Sift (1, P2);
        V[D][Dose]+=Inf;
        Sift (1, D);
    }
    for (int i=1; i<=NH[P2]; ++i)
    {
        S2=Max (S2, V[P2][i]);
    }
}

void Print ()
{
    freopen ("fabrica.out", "w", stdout);
    printf ("%d %d\n", S1, S2);
}

int main()
{
    Read ();
    ProcessA ();
    ProcessB ();
    Print ();
    return 0;
}