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

Bài tập thuộc lộ trình

1 lộ trình

Xếp hàng phục vụ (Queue)

Queue

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn people and person ii needs tit_i 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 nn; the second contains t1,…,tnt_1,\ldots,t_n.

Output

Print the maximum number of satisfied people.

Subtasks

  • Subtask 1 (20 points): 1≤n≤241\le n\le 24; 1≤ti≤1091\le t_i\le10^9 for every ii.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le 2000; 1≤ti≤1091\le t_i\le10^9 for every ii.
  • Subtask 3 (50 points): 1≤n≤1000001\le n\le 100000; 1≤ti≤1091\le t_i\le10^9 for every ii.

Examples

Input

5
15 2 1 5 3

Output

4

Explanation

Order the service times as 1,2,3,5,151,2,3,5,15. The waiting times are 0,1,3,6,110,1,3,6,11; all except the person with service time 55 wait no longer than their service time. The optimum is 44.