#abc288e. E - Wish List
E - Wish List
Score : points
问题描述
在一家商店中有 件商品,编号分别为 Item , Item , , Item 。
对于每个 ,Item 的常规价格是 日元。每种商品库存中只有一件。
高桥想要 件商品:Item , Item , , Item 。
他将重复以下操作直到获取所有他想要的商品:
设 为当前未售出商品的数量。选择一个整数 使得 ,然后以该商品的常规价格加上 日元的价格购买未售出商品中第 小的商品编号对应的商品。
请输出获取高桥想要的所有商品所需的最小总金额。
高桥也可以购买他不想要的商品。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There are items in a shop, numbered as Item , Item , , Item .
For each , the regular price of Item is yen. For each item, there is only one in stock.
Takahashi wants items: Item , Item , , Item .
He repeats the following until he gets all items he wants.
Let be the number of unsold items now. Choose an integer such that , and buy the item with the -th smallest item number among the unsold items, for its regular price plus yen.
Print the smallest total amount of money needed to get all items Takahashi wants.
Takahashi may also buy items other than the ones he wants.
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
5 2
3 1 4 1 5
9 2 6 5 3
3 5
Sample Output 1
17
Here is a way for Takahashi to get all items he wants with the smallest total amount of money.
- Initially, five items, Items , are remaining. Choose to buy the item with the fifth smallest item number among the remaining, Item , for yen.
- Then, four items, Items , are remaining. Choose to buy the item with the second smallest item number among the remaining, Item , for yen.
- Then, three items, Items , are remaining. Choose to buy the item with the second smallest item number among the remaining, Item , for yen.
Now, Takahashi has all items he wants, Items and , (along with Item , which is not wanted) for a total cost of yen, the minimum possible.
Sample Input 2
20 8
29 27 79 27 30 4 93 89 44 88 70 75 96 3 78 39 97 12 53 62
32 38 84 49 93 53 26 13 25 2 76 32 42 34 18 77 14 67 88 12
1 3 4 5 8 14 16 20
Sample Output 2
533
update @ 2024/3/10 12:02:28