Cod sursa(job #585873)

Utilizator ProcopliucProcopliuc Adrian Procopliuc Data 30 aprilie 2011 12:22:55
Problema Fabrica Scor 2
Compilator cpp Status done
Runda Algoritmiada 2011, Runda Finală, Open Marime 1.35 kb
# include <fstream>
# include <algorithm>
using namespace std;
ifstream f ("fabrica.in");
ofstream g ("fabrica.out");
int a[50005],b[50005],na,nb,i,n,s=0,t[50005],nt[50005],ok,mm,j,k,m,q;

   int calc (int x)
   {
       int i=1,s=0;
       while (i<=na)
       if (x/a[i])
       {
           s+=x/a[i];
           i++;
       }
       else
       break;

       return s;

   }

    int calc2(int x)
    {
         int i=1,s=0;
       while (i<=nb)
       if (x/a[i])
       {
           s+=x/b[i];
           i++;
       }
       else
       break;

       return s;

    }

int main ()
{

    f>>n>>na>>nb;
    for (i=1;i<=na;i++)
    f>>a[i];

    for (i=1;i<=nb;i++)
    f>>b[i];

    sort (a+1,a+na+1);
    sort (b+1,b+nb+1);


    ok=0;
    j=0;
    q=1;
    while (ok==0)
    {
        k=calc(q);
        if (k-s)
        {
         j++;
         t[j]=q;
        if (k>=n)
        {

            nt[j]=n-s;
            ok=1;

        }
        else
        {

            nt[j]=k-s;
            s+=nt[j];
        }

        }
    q++;

    }


    g<<t[j]<<" ";
    m=j;


        ok=0;
    j=0;
    q=t[m];
    while (ok==0)
    {
        k=calc2(q);
        if (k>=n)
        {

            g<<q+a[1];
            ok=1;

        }
    q++;

    }


    return 0;

}