PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000262. Hỗ trợ chi phí đi lại (Transportation Expenses)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Hỗ trợ chi phí đi lại (Transportation Expenses)
Transportation Expenses
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Takahashi runs an event attended by people, with individual travel costs yen. For a nonnegative integer cap , person receives yen. Given budget , determine the greatest affordable cap, or report that no finite upper bound is necessary.
Input
The first line contains integers .
The second line contains integers .
Output
Print the greatest integer cap, or infinite if unbounded.
Subtasks
- Subtask 1 (20 points): ; ; ().
- Subtask 2 (30 points): ; ; (); .
- Subtask 3 (50 points): ; ; ().
Examples
Input 1
4 8
1 3 2 4
Output 1
2
Explanation
Cap 2 pays 1, 2, 2, 2, totaling 7; cap 3 costs 9, exceeding 8. Thus 2 is maximal.
Input 2
3 20
5 3 2
Output 2
infinite
Explanation
The total actual cost is only 10, so any cap remains within 20.