Pagini recente » Cod sursa (job #1471164) | Cod sursa (job #585879)
Cod sursa(job #585879)
# 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[500005],nt[500005],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;
}