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

#BS0000272. Cà phê và bài luận (bản khó) (Coffee and Coursework (Hard Version))

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Cà phê và bài luận (bản khó) (Coffee and Coursework (Hard Version))

Coffee and Coursework (Hard Version)

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Polycarp needs to write at least mm pages using nn cups of coffee with energy values aia_i. Each cup may be consumed once at most, in any order. The jj-th cup consumed on a day contributes max⁡(0,a−j+1)\max(0,a-j+1) pages if its energy is aa. The counter resets each day; without coffee no pages are written. Find the minimum number of days or report impossibility.

Input

The first line contains n,mn,m. The second line contains nn integers aia_i.

Output

Print the minimum days, or -1 if impossible.

Subtasks

  • Subtask 1 (20 points): 1≤n≤71\le n\le7; 1≤m≤701\le m\le70; 1≤ai≤101\le a_i\le10 (1≤i≤n1\le i\le n).
  • Subtask 2 (30 points): 1≤n≤2⋅1051\le n\le2\cdot10^5; 1≤m,ai≤1091\le m,a_i\le10^9 (1≤i≤n1\le i\le n); a1=⋯=ana_1=\cdots=a_n.
  • Subtask 3 (50 points): 1≤n≤2⋅1051\le n\le2\cdot10^5; 1≤m,ai≤1091\le m,a_i\le10^9 (1≤i≤n1\le i\le n).

Examples

Input 1

5 16
5 5 5 5 5

Output 1

2

Explanation

One day yields only 15 pages. Four cups on one day and one on the next yield 14+5=19.

Input 2

5 26
5 5 5 5 5

Output 2

-1

Explanation

Total energy is 25, below 26.