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
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
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 pages using cups of coffee with energy values . Each cup may be consumed once at most, in any order. The -th cup consumed on a day contributes pages if its energy is . 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 . The second line contains integers .
Output
Print the minimum days, or -1 if impossible.
Subtasks
- Subtask 1 (20 points): ; ; ().
- Subtask 2 (30 points): ; (); .
- Subtask 3 (50 points): ; ().
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.