Description
在byteotian公司搬家的时候,他们发现他们的大量的精密砝码的搬运是一件恼人的工作。公司有一些固定容
量的容器可以装这些砝码。他们想装尽量多的砝码以便搬运,并且丢弃剩下的砝码。每个容器可以装的砝码数量有
限制,但是他们能够装的总重量不能超过每个容器的限制。一个容器也可以不装任何东西。任何两个砝码都有一个
特征,他们的中总有一个的重量是另外一个的整数倍,当然他们也可能相等。
Input
第一行包含两个数n和m。表示容器的数量以及砝码的数量。(1<=n, m<=100000) 第二行包含n个整数wi,表示
每个容器能够装的最大质量。(1<=wi<=1000000000) 第三行包含m个整数mj,表示每个砝码的质量。(1<=mj<=10000
00000)
Output
仅包含一个数,为能够装进容器的最多的砝码数量。
Sample Input
2 4
13 9
4 12 2 4
13 9
4 12 2 4
Sample Output
3
HINT
http://hzwer.com/4761.html
1 #include<iostream> 2 #include<cstdlib> 3 #include<cmath> 4 #include<cstring> 5 #include<cstdio> 6 #include<algorithm> 7 #include<string> 8 #include<map> 9 #include<queue> 10 #include<vector> 11 #include<set> 12 #define inf 1000000000 13 #define maxn 100000+5 14 #define maxm 10000+5 15 #define eps 1e-10 16 #define ll long long 17 #define for0(i,n) for(int i=0;i<=(n);i++) 18 #define for1(i,n) for(int i=1;i<=(n);i++) 19 #define for2(i,x,y) for(int i=(x);i<=(y);i++) 20 #define for3(i,x,y) for(int i=(x);i>=(y);i--) 21 #define for4(i,x) for(int i=head[x],y=e[i].go;i;i=e[i].next,y=e[i].go) 22 using namespace std; 23 int read(){ 24 int x=0,f=1;char ch=getchar(); 25 while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} 26 while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();} 27 return x*f; 28 } 29 int n,m,tot; 30 int a[maxn],b[maxn]; 31 int c[55],cnt[55]; 32 bool jud(int now){ 33 for(int i=now+1;i<=tot;i++) 34 if(cnt[i]){ 35 cnt[now]+=c[i]/c[now]; 36 cnt[i]--; 37 return 1; 38 } 39 return 0; 40 } 41 int main(){ 42 //freopen("input.txt","r",stdin); 43 //freopen("output.txt","w",stdout); 44 n=read();m=read(); 45 for1(i,n)a[i]=read(); 46 for1(i,m)b[i]=read(); 47 sort(b+1,b+m+1); 48 for1(i,m) 49 if(b[i]!=b[i-1]) 50 c[++tot]=b[i]; 51 for1(i,n) 52 for(int j=tot;j;j--) 53 while(c[j]<=a[i]){ 54 a[i]-=c[j]; 55 cnt[j]++; 56 } 57 int now=1; 58 for1(i,m){ 59 while(b[i]>c[now])now++; 60 if(cnt[now])cnt[now]--; 61 else if(jud(now))cnt[now]--; 62 else{ 63 printf("%d\n",i-1); 64 return 0; 65 } 66 if(i==m)printf("%d\n",m); 67 } 68 return 0; 69 }