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

#BS0000270. Kế hoạch tài chính (Financial Planning)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Kế hoạch tài chính (Financial Planning)

Financial Planning

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

You need at least MM euros net to retire. Starting with no cash, you may borrow any amount interest-free. Each of nn investment opportunities can be purchased once for cic_i euros and returns pip_i euros per day. Choose any subset at the start and repay the entire loan after an integer number of days. Find the earliest day at which at least MM euros remain.

Input

The first line contains n,Mn,M. Each of the next nn lines contains pi,cip_i,c_i, daily earnings followed by initial cost.

Output

Print the minimum number of days.

Subtasks

  • Subtask 1 (20 points): 1≤n≤81\le n\le8; 1≤M,pi,ci≤501\le M,p_i,c_i\le50 (1≤i≤n1\le i\le n).
  • Subtask 2 (30 points): 1≤n≤1051\le n\le10^5; 1≤M,pi,ci≤1091\le M,p_i,c_i\le10^9 (1≤i≤n1\le i\le n); p1=⋯=pnp_1=\cdots=p_n; c1=⋯=cnc_1=\cdots=c_n.
  • Subtask 3 (50 points): 1≤n≤1051\le n\le10^5; 1≤M,pi,ci≤1091\le M,p_i,c_i\le10^9 (1≤i≤n1\le i\le n).

Examples

Input 1

2 5
4 10
10 15

Output 1

2

Explanation

After two days the second option nets 20-15=5. Neither option is profitable after one day.