Answer for Cooling Pies Wrong, have tried multiple test cases.

Problem Link - http://www.codechef.com/problems/COOLING

I think this is maybe because if there are 5 pies of 0 weight, and 5 machines with weight limit 0, I’m not sure whether to display 5 or 0…

Currently my program will display 5.

#include<cstdio>

int noofpies(int n,int a[101],int b[101])
{
    int m=0,c[101],d[101],e[30],f[30],c1=0,c2=0;
    for(int i=0;i<101;i++)
    {
        c[i]=-1;
        d[i]=-1;

    }
    for(int j=0;j<n;j++)
    {
        c[a[j]]++;
        d[b[j]]++;
    }
    for(int l=0;l<101;l++)
    {
        if(c[l]>=0)
        {
            while(c[l]-->=0)
            {
                e[c1]=l;
                c1++;
            }
        }
        if(f[l]>=0)
        {
            while(d[l]-->=0)
            {
                f[c2]=l;

                c2++;
            }
        }
    }
    for(int k=0;k<n;k++)
    {
        if(e[m]<=f[k])
        {
            m++;
        }
    }

    return m;

}

int main()
{

    int t,n,a[101],b[101];
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);

        }
        for(int j=0;j<n;j++)
        {
            scanf("%d",&b[j]);
        }
        printf("%d\n",noofpies(n,a,b));
    }
    return 0;
}

Okay I found the error myself…

The line which says if(f[l]>=0) should actually be if(d[l]>=0).

I’ve tried modifying it such that it does not count pies with weight 0, but still I get a wrong answer.