PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000250. Thời gian sửa ô tô ít nhất (Minimum Time to Repair Cars)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Thời gian sửa ô tô ít nhất (Minimum Time to Repair Cars)
Minimum Time to Repair Cars
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
There are mechanics, numbered 1 through . There are cars waiting to be repaired; all of them must be repaired. Mechanic has rank and needs minutes to repair cars. All mechanics can work independently and simultaneously from time zero. Find the minimum time required.
Input
The first line contains integers , the number of mechanics and required cars.
The second line contains integers , the ranks of the mechanics.
Output
Print the minimum time as one integer.
Subtasks
- Subtask 1 (20 points): ; ; for every .
- Subtask 2 (30 points): ; ; for every . .
- Subtask 3 (50 points): ; ; for every .
Examples
Input
4 10
4 2 3 1
Output
16
Explanation
In 16 minutes the mechanics can repair 2, 2, 2, and 4 cars, totaling 10. In 15 minutes they can repair only 1, 2, 2, and 3, totaling 8. Hence 16 minutes are necessary.