PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000062. Xếp hàng phục vụ (Queue)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Xếp hàng phục vụ (Queue)
Queue
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are people and person needs time units for service. You may reorder the queue arbitrarily. A person is satisfied if their waiting time, the sum of service times before them, does not exceed their own service time. Maximize the number of satisfied people.
Input
The first line contains ; the second contains .
Output
Print the maximum number of satisfied people.
Subtasks
- Subtask 1 (20 points): ; for every .
- Subtask 2 (30 points): ; for every .
- Subtask 3 (50 points): ; for every .
Examples
Input
5
15 2 1 5 3
Output
4
Explanation
Order the service times as . The waiting times are ; all except the person with service time wait no longer than their service time. The optimum is .