#BS0000252. Số ngày ít nhất để làm đủ bó hoa (Minimum Number of Days to Make m Bouquets)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Số ngày ít nhất để làm đủ bó hoa (Minimum Number of Days to Make m Bouquets)
Minimum Number of Days to Make m Bouquets
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
There are flowers in a row, numbered 1 through . Flower becomes available on day . You need bouquets, each containing exactly consecutive flowers in the original row. Each flower may be used in at most one bouquet. Find the earliest day when all bouquets can be made, or determine that this is impossible.
Input
The first line contains : the number of flowers, bouquets required and flowers per bouquet.
The second line contains exactly integers , representing the blooming days.
Output
Print the earliest feasible day, or -1 if impossible.
Subtasks
- Subtask 1 (20 points): ; for every ; ; .
- Subtask 2 (30 points): ; for every ; ; ; .
- Subtask 3 (50 points): ; for every ; ; .
Examples
Input
7 2 3
7 7 7 7 12 7 7
Output
12
Explanation
On day 7 the available runs are positions 1–4 and 6–7. Only the first run yields a bouquet of three. Nothing changes before day 12. On day 12, positions 1–3 and 4–6 form two disjoint bouquets, so 12 is minimal.