# 3 1 # 1 2 # 1 3 # 2 3 # # 3
# 3 2 # 1 2 # 1 3 # 2 3 # # 2
第一行n,m表示n次放菜m表示每次夹菜后等待时间
下面n行表示第几秒开始放菜,多久菜煮熟
def solve_method(n, m, x, y): arrTime = [x[i]+y[i] for i in range(n)] arrTime.sort() print("arrTime",arrTime) #arrTime [3, 4, 5] arrCount = [0 for i in range(n)] next = 0 arrCount[0] = 1 for i in range(1, n): # 上一时刻手速慢的话 即等待时间长太长,就吃不到当前菜 if arrTime[i] >= (arrTime[next] + m): arrCount[i] = 1 next = i print(sum(arrCount)) if __name__ == '__main__': split = input().split(' ') n, m = int(split[0]), int(split[1]) x, y = [], [] for i in range(n): xx, yy = map(int, input().split()) x.append(xx) y.append(yy) solve_method(n, m, x, y)