PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000064. Tái sử dụng máy trạm (Workstations)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Tái sử dụng máy trạm (Workstations)

Workstations

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

A lab has enough workstations. Researcher ii arrives at time aia_i and uses a workstation continuously for sis_i minutes. A workstation remains unlocked for mm minutes after use and then locks if idle. Busy workstations cannot be shared, and all machines are initially locked. Maximize the number of unlock operations saved compared with unlocking a workstation for every researcher.

Input

The first line has n,mn,m. The next nn lines have ai,sia_i,s_i, the arrival time and usage duration of researcher ii.

Output

Print the maximum number of unlock operations that can be saved.

Subtasks

  • Subtask 1 (20 points): 1≤n≤241\le n\le 24; 1≤m≤1081\le m\le10^8; 1≤ai,si≤1081\le a_i,s_i\le10^8 for every ii.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le 2000; 1≤m≤1081\le m\le10^8; 1≤ai,si≤1081\le a_i,s_i\le10^8 for every ii.
  • Subtask 3 (50 points): 1≤n≤3000001\le n\le 300000; 1≤m≤1081\le m\le10^8; 1≤ai,si≤1081\le a_i,s_i\le10^8 for every ii.

Examples

Input

3 5
1 3
4 2
9 1

Output

2

Explanation

The first person finishes at time 44; the second arrives at 44 and reuses that machine. The second finishes at 66, and the third arrives at 99, within the 55-minute grace period. Two unlock operations are saved.