check this test case

i/p
2 1 5
1 9
0

o/p
 9

your code gives 12...
--


Amol Sharma
Third Year Student
Computer Science and Engineering
MNNIT Allahabad
 <http://gplus.to/amolsharma99>
<http://twitter.com/amolsharma99><http://in.linkedin.com/pub/amol-sharma/21/79b/507><http://youtube.com/amolsharma99>





On Tue, Aug 30, 2011 at 10:27 PM, saurabh singh <saurab...@gmail.com> wrote:

> I am repeatedly getting Wrong answer for this problem.I am  not sure where
> I am going wrong.....
> I am finding the intersection point by the normal algorithm(Maintaining two
> pointers and moving forward the smaller one and I am then concating the
> elements into their sum about the intersection point) Working for all cases
> given in comments,forums.and anything else I can think of,,,,,,,
>
> #include<stdio.h>
> int main()
>         {
>         int a[10001],b[10001];
>         int i,j;
>         int n,m;
>         while(scanf("%d",&n)&&n)
>                 {
>                 for(i=0;i<n;i++)        scanf("%d",&a[i]);
>                 scanf("%d",&m);
>                 for(j=0;j<m;j++)
>                         scanf("%d",&b[j]);
>                 int c[10001]={0},d[10001]={0};
>                 i=j=0;
>                 int k=0,l=0;
>                 long long sum=0;
>                 for(i=0,j=0;i<n&&j<m;)
>                         {
>                         int flag=0;
>                         if(a[i]==b[j])
>                                 {
>                                 c[k]+=a[i];
>                                 d[l]+=b[j];
>                                 //sum=0;
>                                 k++;
>                                 l++;
>                                 flag=1;
>                                 i++;j++;
>                         }
>
>
>                         if(a[i]<b[j]&&!flag) {
>
>                         c[k]+=a[i];
>                         i++;
>                         }
>                         else if(a[i]>b[j]&&!flag){
>                          d[l]+=b[j];
>
>                          j++;
>                          }
>                         //if(a[i]==b[j]) i++;j++;
>
>                 }
>                 if((!i)||(!j)) i=j=0;
>                 for(;j<m;j++) d[l]+=b[j];
>                 for(;i<n;i++) c[k]+=a[i];
>                 k++;
>                 l++;
>                 for(i=0,j=0;i<k&&j<l;i++,j++)
>                         {
>                         if(c[i]>d[j]) sum+=c[i];
>                         else sum+=d[j];
>                         }
>                 #ifdef DEB
>                 for(i=0;i<k;i++)
>                         printf("%d\t",c[i]);
>                 puts("");
>                 for(j=0;j<l;j++)
>                         printf("%d\t",d[j]);
>                 puts("");
>                 #endif
>                 printf("%lld\n",sum);
>                 }
>         return 0;
>         }
>
>
> --
> Saurabh Singh
> B.Tech (Computer Science)
> MNNIT ALLAHABAD
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to