Pagini recente » Cod sursa (job #1322308) | Cod sursa (job #328644) | Cod sursa (job #3192835) | Cod sursa (job #1470378) | Cod sursa (job #833018)
Cod sursa(job #833018)
#include <stdio.h>
#include <algorithm>
#define LMax 50010
#define NMax 100010
using namespace std;
const char IN[]="fabrica.in",OUT[]="fabrica.out";
int N,NA,NB,Rez,Rez2;
int A[LMax],B[LMax],C[LMax];
int v[NMax];
bool test2(int L)
{
int i,j,r,n=0,p,pp;
for (i=1;i<=NB;++i) C[i]=L-B[i];
for (j=N,p=0;j>0;--j,p=(p+1)%NB)
{
pp=p+1;
if (pp==1 && C[pp]<v[j]) return false;
if (C[pp]<v[1] || C[pp]<v[j]) {++j;continue;}
C[pp]-=B[pp];
}
return true;
}
int search2(int L)
{
int i,step;
for (step=1;step<L;step<<=1);
for (i=L;step;step>>=1)
if (i-step>0 && test2(i-step))
i-=step;
return i;
}
bool test(int L)
{
int i,r=0;
for (i=1;i<=NA;++i)
r+=L/A[i];
return r>=N;
}
int search(int L)
{
int i,step;
for (step=1;step<L;step<<=1);
for (i=L;step;step>>=1)
if (i-step>0 && test(i-step))
i-=step;
return i;
}
int main()
{
int i,j,c,n;
freopen(IN,"r",stdin);
scanf("%d%d%d",&N,&NA,&NB);
for (i=1;i<=NA;++i) scanf("%d",A+i);
for (i=1;i<=NB;++i) scanf("%d",B+i);
fclose(stdin);
sort(A+1,A+NA+1);
sort(B+1,B+NB+1);
Rez =search(N*A[1]);
n=0;
for (i=1;i<=NA;++i)
{
c=Rez/A[i];
for (j=1;n<N && j<=c;++j)
v[++n]=j*A[i];
}
sort(v+1,v+N+1);
test2(5);
Rez2=search2((1<<30)-1);
freopen(OUT,"w",stdout);
printf("%d %d\n",Rez,Rez2);
fclose(stdout);
return 0;
}