paizaスキルチェックが上手くいかない。

Cでもpython3でもタイムオーバーしてしまう。

==================================================

#A025:動物の体調管理
# coding: utf-8
# 自分の得意な言語で
# Let's チャレンジ!!
def check_diet(depth,max_depth,d,S,T,ans):
a=d[depth][0]
b=d[depth][1]
if(depth==(max_depth-1)):
w=S+b
if(w<=T):
ans=ans+1
w=S-a
if(w<=T):
ans=ans+1
return ans
w=S+b
if(w<=T):
ans=check_diet(depth+1,max_depth,d,w,T,ans)
w=S-a
if(w<=T):
ans=check_diet(depth+1,max_depth,d,w,T,ans)
return ans

input_lines = input()
lines=input_lines.split()
N=int(lines[0])
S=int(lines[1])
T=int(lines[2])
d=
for i in range(N):
input_lines = input()
lines=input_lines.split()
a=int(lines[0])
b=int(lines[1])
d.append([a,b])
ans=check_diet(0,N,d,S,T,0)
print(ans)

==================================================

 

#A025:動物の体調管理
#include <stdio.h>
#include <stdio.h>
#include <math.h>

static void check_diet(int,int,int [2],int,int,int*);

static void check_diet(int depth, int max_depth, int pat[][2],int S, int T, int *ans) {
int i;
//printf("n: %d check_array: %s\n",n,check_array);
int a,b;
a=pat[depth][0];
b=pat[depth][1];
int w;
//printf("depth: %d weight: %d\n",depth,w);
int ret=0;
w=S+b;
if(depth==max_depth-1) {
if(w<=T)
(*ans)++;
// (S-a)<T
(*ans)++;
return;
}
if(w<=T)
check_diet(depth+1,max_depth,pat,w,T,ans);
w=S-a;
check_diet(depth+1,max_depth,pat,w,T,ans);
return;
}

int main(void){
// 自分の得意な言語で
// Let's チャレンジ!!

char str[1000];
fgets(str, sizeof(str), stdin);
int N,S,T;
sscanf(str,"%d %d %d",&N,&S,&T);
//printf("%d %d %d\n",N,S,T);
int pat[N][2];
int i;
for(i=0; i<N; i++) {
int a,b;
fgets(str, sizeof(str), stdin);
sscanf(str,"%d %d",&a,&b);
//printf("%d %d\n",a,b);
pat[i][0]=a;
pat[i][1]=b;
//printf("N: %d S: %d T: %d",N,S,T);
}
//printf("max: %d\n",imax);
int ans=0;
check_diet(0,N,pat,S,T,&ans);
printf("%d\n",ans);
return 0;
}