P29954 [洛谷] [EGOI2021] Shopping Fever
普及+
题目描述

Problem Description

Heidi is in a large store. She wants to buy $n$ items.

Today is her lucky day. The store is running a promotional event: for each bill, customers receive one of the following discounts:

  1. If at least $3$ items are bought, the cheapest one is free.
  2. If fewer than $3$ items are bought, the bill receives a $q\%$ discount.

Heidi wants to buy all $n$ items without repetition. She can split her purchases into any number of bills. Each bill will be discounted according to the corresponding promotion policy.

What is the minimum amount of money she needs to spend to buy all $n$ items?

Input Format

The first line contains two integers $n, q$ — the number of items and the discount percentage for fewer than $3$ items.

The second line contains $n$ integers $p_i$ — the prices of the items.

Additionally, it is guaranteed that the item prices are divisible by $100$. Therefore, the discounted price for each bill will always be an integer.

Output Format

A single line containing one integer — the minimum amount of money needed.

Sample Input and Output

Sample Input #1

7 10
300 200 200 300 100 300 200

Sample Output #1

1090

Sample Input #2

3 20
1000 500 100

Sample Output #2

1280

Sample Input #3

4 0
200 100 300 200

Sample Output #3

600

Notes

Sample 1 Explanation

Heidi first buys three items priced at $200, costing $400 (one item is free). Then she buys three items priced at $300, costing $600 (one item is free again). Finally, she buys the remaining item priced at $100, receiving a $10\%$ discount.


Sample 2 Explanation

If Heidi buys all three items in one bill, she gets a [MATH14]\cdot\frac{20}{100}=320$.


Data Range

For all data, $1\le n\le 10^5$, $0\le q\le 100$, $100\le p_i\le 10^5$ and $100\mid p_i$.

  • Subtask 1 (8 points): $n=3$, $100\le p_i\le 10^3$.
  • Subtask 2 (18 points): $q=0$.
  • Subtask 3 (16 points): $q=40$.
  • Subtask 4 (22 points): $100\le p_i\le 10^3$.
  • Subtask 5 (36 points): No additional constraints.
输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
7 10 300 200 200 300 100 300 200
样例输出
1090