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

#GD0000108. Cắt rau đều nhau (Boiling Vegetables)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Cắt rau đều nhau (Boiling Vegetables)

Boiling Vegetables

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

You have nn vegetable pieces of weights wiw_i. In one cut, any piece can be split into two positive real weights summing to its original weight. Find the fewest cuts so the smallest resulting piece divided by the largest is strictly greater than TT, where 0.5<T<10.5<T<1. The optimum is less than 500500 and unchanged if TT increases by 0.00010.0001.

Input

Line 1 contains decimal TT with two fractional digits and integer nn. Line 2 contains nn integer weights wiw_i.

Output

Print the minimum number of cuts.

Subtasks

  • Subtask 1 (20 points): 0.50<T<1.000.50<T<1.00 (hai chữ số thập phân); 1≤n≤121\le n\le 12; 1≤wi<1061\le w_i<10^6; đáp án <500<500; nghiệm không đổi khi TT tăng thêm 0.00010.0001.
  • Subtask 2 (30 points): 0.50<T<1.000.50<T<1.00 (hai chữ số thập phân); 1≤n≤1501\le n\le 150; 1≤wi<1061\le w_i<10^6; đáp án <500<500; nghiệm không đổi khi TT tăng thêm 0.00010.0001.
  • Subtask 3 (50 points): 0.50<T<1.000.50<T<1.00 (hai chữ số thập phân); 1≤n≤10001\le n\le 1000; 1≤wi<1061\le w_i<10^6; đáp án <500<500; nghiệm không đổi khi TT tăng thêm 0.00010.0001.

Examples

Input

0.80 2
1000 1400

Output

3

Explanation

Initially 1000/1400<0.81000/1400<0.8. Cut 10001000 into two 500500 pieces. Cut 14001400 into 1400/31400/3 and 2800/32800/3, then cut the latter into two 1400/31400/3 pieces. After three cuts the ratio is about 466.67/500=0.933>0.8466.67/500=0.933>0.8.