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

#GD0000099. Sắp lịch học tối đa (Course Schedule III)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Sắp lịch học tối đa (Course Schedule III)

Course Schedule III

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

You have nn courses. Course ii requires tit_i consecutive days and must finish by day did_i. Starting on day 1, you can take only one course at a time, in any chosen order. You may skip courses. Find the maximum number of courses completed.

Input

Line 1 contains nn. Each of the following nn lines contains ti,dit_i,d_i.

Output

Print the maximum number of completed courses.

Subtasks

  • Subtask 1 (20 points): 1≤n≤121\le n\le 12; 1≤ti,di≤1041\le t_i,d_i\le10^4 for every ii.
  • Subtask 2 (30 points): 1≤n≤15001\le n\le 1500; 1≤ti,di≤1041\le t_i,d_i\le10^4 for every ii.
  • Subtask 3 (50 points): 1≤n≤100001\le n\le 10000; 1≤ti,di≤1041\le t_i,d_i\le10^4 for every ii.

Examples

Input

4
100 200
200 1300
1000 1250
2000 3200

Output

3

Explanation

Take courses 11, 33, 22 to finish at days 100100, 11001100, 13001300, each no later than its deadline. No fourth course can be added; the maximum is 33.