This page is still under construction.

Parts of this page are still being built. What you see may change.

Shopping Fever

Time limit1sMemory limit512 MB

Summary
Given n prices and a discount rate q, split the items into purchases so the total paid is minimized, where any purchase of 3 or more items gives the cheapest item free.
Level

Medium5 of 10

Topics
Dynamic programming, Greedy, Sorting, Array
Solved
No attempts yet

Problem

Heidi is in a big store. She would like to purchase nn items.

Today is her lucky day. The store runs a special sale: on every purchase, the customer receives one of the following two promotions:

  1. When at least 33 items are bought together, the cheapest one is free.
  2. When fewer than 33 items are bought together, the customer gets a q%q\% discount on the purchase.

Heidi would like to buy all nn items on her shopping list, each exactly once. She can make an arbitrary number of purchases. For each purchase she'll make, the appropriate promotion will apply.

What is the minimum total price she has to pay to buy all nn items?

Input

The first line contains two single space-separated integers nn (1≤n≤100 0001 \le n \le 100\,000) and qq (0≤q≤1000 \le q \le 100) — the number of items Heidi wants to buy and the percentage discount she gains for purchases of fewer than three items.

The following line contains nn single space separated integers p_1,…,p_np\_1, \dots, p\_n — the prices of the goods (100≤p_i≤100 000100 \le p\_i \le 100\,000, 1≤i≤n1 \le i \le n).

Additionally, it is guaranteed that each p_ip\_i will always be divisible by 100100. Hence, the discounted price of each purchase will always be an integer.

Output

Output a single integer — the minimum total price Heidi has to pay in order to buy all nn items.

Hint

First, Heidi can buy the three items that cost 200200 in a single transaction for 400400 (she gets one of them for free). Then she can purchase the three items that cost 300300 for 600600 (again, one is free). Finally, she can purchase the last remaining item (with cost 100100) with a 10%10\% discount.

In the second example test, if Heidi buys all three items in a single transaction, she receives discount of 100100. However, if she buys each item individually, her discount will be (1000+500+100)⋅20/100=320(1000 + 500 + 100) \cdot 20 / 100 = 320.

Examples3

  1. Example 1

    Input
    7 10
    300 200 200 300 100 300 200
    
    Expected output
    1090
    
  2. Example 2

    Input
    3 20
    1000 500 100
    
    Expected output
    1280
    
  3. Example 3

    Input
    4 0
    200 100 300 200
    
    Expected output
    600