Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/10000 K (Java/Others)
Total Submission(s): 42890 Accepted Submission(s): 10395
1 #include<bits/stdc++.h> 2 using namespace std; 3 int l[1005],n[1005],m[1005],c[250005]; 4 int ef(int l,int n,int m){ 5 int mid; 6 while(l<=n){ 7 mid=(l+n)/2; 8 if(c[mid]>m) 9 n=mid-1; 10 else if(c[mid]<m) 11 l=mid+1; 12 else 13 return -1; 14 } 15 return 1; 16 } 17 int main(){ 18 int a,b,s,x,p; 19 int i,j,h,num=0,len,ans; 20 while(~scanf("%d%d%d",&a,&b,&s)){ 21 for(i=0;i<a;i++) 22 scanf("%d",&l[i]); 23 for(i=0;i<b;i++) 24 scanf("%d",&n[i]); 25 for(i=0;i<s;i++) 26 scanf("%d",&m[i]); 27 h=0; 28 for(i=0;i<a;i++){ 29 for(j=0;j<b;j++) 30 c[h++]=l[i]+n[j]; 31 } 32 len=a*b; 33 sort(c,c+len); 34 scanf("%d",&p); 35 printf("Case %d:\n",++num); 36 while(p--){ 37 scanf("%d",&x); 38 for(i=0;i<s;i++){ 39 ans=ef(1,len,x-m[i]); 40 if(ans==-1) 41 break; 42 } 43 if(ans==1) 44 printf("NO\n"); 45 else 46 printf("YES\n"); 47 } 48 } 49 return 0; 50 }