PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000276. Phân phối hàng hóa tối ưu (Minimized Maximum of Products Distributed to Any Store)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Phân phối hàng hóa tối ưu (Minimized Maximum of Products Distributed to Any Store)

Minimized Maximum of Products Distributed to Any Store

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn stores and mm product types, with aia_i items of type ii. Distribute all items; each store may receive at most one type and may remain empty. Minimize the largest number of items assigned to any store.

Input

First line: n,mn,m. Second line: mm integers aia_i.

Output

Print the optimal value.

Subtasks

  • Subtask 1 (20 points): 1≤m≤n≤121\le m\le n\le12; 1≤ai≤301\le a_i\le30 (1≤i≤m1\le i\le m).
  • Subtask 2 (30 points): 1≤m=n≤1051\le m=n\le10^5; 1≤ai≤1051\le a_i\le10^5 (1≤i≤m1\le i\le m).
  • Subtask 3 (50 points): 1≤m≤n≤1051\le m\le n\le10^5; 1≤ai≤1051\le a_i\le10^5 (1≤i≤m1\le i\le m).

Examples

Input 1

6 2
11 6

Output 1

3

Explanation

The first type uses loads 3,3,3,2 and the second uses 3,3. A cap of 2 requires nine stores, exceeding six.