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

#TP0000040. Tối đa hóa giá bán (Price Maximization)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Tối đa hóa giá bán (Price Maximization)

Price Maximization

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn goods, where nn is even, and good ii weighs aia_i. Partition all goods into exactly n/2n/2 pairs. A package of total weight xx sells for ⌊x/k⌋\lfloor x/k\rfloor. Find the maximum total revenue over all packages.

Input

  • The first line contains integers n,kn,k: the number of goods and the price divisor.
  • The second line contains nn integers a1,…,ana_1,\ldots,a_n, their weights.

Output

Print the maximum total revenue after pairing all goods.

Subtasks

  • Subtask 1 (20 points): 2≤n≤82\le n\le8; 2≤n2\le n and nn even; 1≤k≤10001\le k\le1000; 0≤ai≤1090\le a_i\le10^9 for all 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 2≤n≤20002\le n\le2000; 2≤n2\le n and nn even; 1≤k≤10001\le k\le1000; 0≤ai≤1090\le a_i\le10^9 for all 1≤i≤n1\le i\le n.
  • Subtask 3 (50 points): 2≤n≤2000002\le n\le200000; 2≤n2\le n and nn even; 1≤k≤10001\le k\le1000; 0≤ai≤1090\le a_i\le10^9 for all 1≤i≤n1\le i\le n.

Examples

Input

6 3
3 2 7 1 4 8

Output

8

Explanation

Pair (7,8)(7,8), (3,4)(3,4), and (2,1)(2,1). Their prices are ⌊15/3⌋=5\lfloor15/3\rfloor=5, ⌊7/3⌋=2\lfloor7/3\rfloor=2, and ⌊3/3⌋=1\lfloor3/3\rfloor=1. The total is 88, which reaches the upper bound ⌊25/3⌋=8\lfloor25/3\rfloor=8.