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

#BS0000281. Vận tốc nhỏ nhất để đến đúng giờ (Minimum Speed to Arrive on Time)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Vận tốc nhỏ nhất để đến đúng giờ (Minimum Speed to Arrive on Time)

Minimum Speed to Arrive on Time

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

Start at time zero and take nn train rides in order, of lengths did_i kilometres. All trains travel at the same positive integer speed vv. Departures occur only at integer hours; transfers at an integer hour require no waiting. No waiting is required after the final ride. Find the smallest speed allowing arrival by HH hours, or −1-1 if impossible.

Input

First line: nn and decimal HH. Second line: nn integers did_i.

Output

Print the smallest positive integer speed, or −1-1.

Subtasks

  • Subtask 1 (20 points): 1≤n≤81\le n\le8; 1≤di≤201\le d_i\le20; 1≤H≤201\le H\le20; HH has at most two decimal places.
  • Subtask 2 (30 points): 1≤n≤1051\le n\le10^5; 1≤di≤1051\le d_i\le10^5; d1=⋯=dnd_1=\cdots=d_n; 1≤H≤1091\le H\le10^9; HH has at most two decimal places.
  • Subtask 3 (50 points): 1≤n≤1051\le n\le10^5; 1≤di≤1051\le d_i\le10^5; 1≤H≤1091\le H\le10^9; HH has at most two decimal places.

Examples

Input 1

3 2.70
1 3 2

Output 1

3

Explanation

Speed 2 needs 1+2+1 hours; speed 3 needs 1+1+2/3 hours, within the deadline.

Input 2

3 1.90
1 3 2

Output 2

-1

Explanation

The final ride cannot depart before hour 2.