Scanf() Vs getchar()

i want to know in which case getchar works faster than scanf().
Actually i was solving the easy level problem “Paying up”. As long as i continued to submit
different solutions using getchar() as the method of input,it kept showing TLE(time limit exceeded) but to my suprise when i submitted those same solution using scanf(),they got submitted in an execution time of less than 1 second.Till now i beleived that getchar() is faster than scanf() as it always worked before but for this question scanf() becomes faster .As you know the limit for this question is 7sec so what scanf() can do in just 0.5 seconds getchar cannot be able to make that up in even 7 seconds.Also if it matters i have submitted my solution in c
*** SO CAN ANYONE PLS TELL ME IN WHICH CASE GATCHAR() IS FASTER THAN SCAN() AND VICE VERSA***

I guess your read function was missing something. It would be better if you can post your code also…

HERE IS MY CODE(which shows time limit exceeded the code which got accepted is exactly the same as one below but i have removed that #define----- and used scanf() whereever input is required
#include<stdio.h>

#define input ch=getchar();\

while(!(ch==’ ‘||ch==’\n’))\

{r=r*10+ch-‘0’;\

ch=getchar();}

int am[21][200001]={0};

int main()

{register int ch=0,r=0,i=0,j=0;

int cases=0,n,m,ar[21]={0},ans[21]={0},a,k,t;

input

cases=r;

r=0;

while(cases–)

{

a=1;

k=0;

input

n=r;

r=0;

input

m=r;

r=0;

for(i=0;i<21;i++)

ans[i]=0;

for(i=0;i<n;i++)

{input

if(r<=m)

{ans[a]=r;

a++;}

r=0;}

if(m>20000)

continue;

k=a-1;

   for(i=0;i<=k;i++)

    am[i][0]=1;

for(i=1;i<=k;i++)

{for(j=0;j<=m;j++)

{if(am[i-1][j]==1)

am[i][j]=1;

if(((j-ans[i])>=0)&&(am[i-1][j-ans[i]]==1))

 am[i][j]=1;

}}

if(am[k][m]==1)

    printf("Yes\n");

if(am[k][m]==0)

printf(“No\n”);

for(i=0;i<=k;i++)

for(j=0;j<=m;j++)

    am[i][j]=0;
}

return 0;}
pls let me know why this shows TLE if getchar reads faster than scanf()