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

#BS0000302. Thời gian chạy đồng thời các máy tính (Maximum Running Time of N Computers)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Thời gian chạy đồng thời các máy tính (Maximum Running Time of N Computers)

Maximum Running Time of N Computers

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn computers and mm batteries with capacities bib_i minutes each. Each computer uses at most one battery at a time and each battery powers at most one computer at a time. At integer times batteries can be swapped instantly, including between computers; no battery can be recharged. Maximize the integer duration for which all computers can run continuously together.

Input

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

Output

Print the maximum number of minutes.

Subtasks

  • Subtask 1 (20 points): 1≤n≤m≤61\le n\le m\le6; 1≤bi≤41\le b_i\le4.
  • Subtask 2 (30 points): 1≤n=m≤1051\le n=m\le10^5; 1≤bi≤1091\le b_i\le10^9.
  • Subtask 3 (50 points): 1≤n≤m≤1051\le n\le m\le10^5; 1≤bi≤1091\le b_i\le10^9.

Examples

Input 1

2 3
3 3 3

Output 1

4

Explanation

Use A on computer 1 for three minutes, B on computer 2 for two, C on computer 2 for the last two, and B on computer 1 for the last minute. Five minutes would require ten battery-minutes.