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

#BS0000277. San bằng ngọn núi trong thời gian ít nhất (Minimum Number of Seconds to Make Mountain Height Zero)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

San bằng ngọn núi trong thời gian ít nhất (Minimum Number of Seconds to Make Mountain Height Zero)

Minimum Number of Seconds to Make Mountain Height Zero

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

A mountain has height HH. There are nn workers operating concurrently. Worker i needs jwij w_i seconds for the j-th unit of height they remove, so removing k units costs wik(k+1)/2w_i k(k+1)/2. Assign exactly H units to minimize the maximum individual completion time.

Input

First line: H,nH,n. Second line: nn integers wiw_i.

Output

Print the minimum number of seconds.

Subtasks

  • Subtask 1 (20 points): 1≤H≤201\le H\le20; 1≤n≤81\le n\le8; 1≤wi≤101\le w_i\le10 (1≤i≤n1\le i\le n).
  • Subtask 2 (30 points): 1≤H≤1051\le H\le10^5; 1≤n≤1041\le n\le10^4; 1≤wi≤1061\le w_i\le10^6 (1≤i≤n1\le i\le n); w1=⋯=wnw_1=\cdots=w_n.
  • Subtask 3 (50 points): 1≤H≤1051\le H\le10^5; 1≤n≤1041\le n\le10^4; 1≤wi≤1061\le w_i\le10^6 (1≤i≤n1\le i\le n).

Examples

Input 1

4 3
2 1 1

Output 1

3

Explanation

Assign 1,2,1 units, taking 2,3,1 seconds. Within two seconds each can remove only one unit.