A8801 | Maxim and Discounts
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Maxim always goes to the supermarket on Sundays. Today the supermarket has a special offer of discount systems.
There are $m$ types of discounts. We assume that the discounts are indexed from 1 to $m$ . To use the discount number $i$ , the customer takes a special basket, where he puts exactly $q_{i}$ items he buys. Under the terms of the discount system, in addition to the items in the cart the customer can receive at most two items from the supermarket for free. The number of the "free items" (0, 1 or 2) to give is selected by the customer. The only condition imposed on the selected "free items" is as follows: each of them mustn't be more expensive than the cheapest item out of the $q_{i}$ items in the cart.
Maxim now needs to buy $n$ items in the shop. Count the minimum sum of money that Maxim needs to buy them, if he use the discount system optimally well.
Please assume that the supermarket has enough carts for any actions. Maxim can use the same discount multiple times. Of course, Maxim can buy items without any discounts.
There are $m$ types of discounts. We assume that the discounts are indexed from 1 to $m$ . To use the discount number $i$ , the customer takes a special basket, where he puts exactly $q_{i}$ items he buys. Under the terms of the discount system, in addition to the items in the cart the customer can receive at most two items from the supermarket for free. The number of the "free items" (0, 1 or 2) to give is selected by the customer. The only condition imposed on the selected "free items" is as follows: each of them mustn't be more expensive than the cheapest item out of the $q_{i}$ items in the cart.
Maxim now needs to buy $n$ items in the shop. Count the minimum sum of money that Maxim needs to buy them, if he use the discount system optimally well.
Please assume that the supermarket has enough carts for any actions. Maxim can use the same discount multiple times. Of course, Maxim can buy items without any discounts.
输入格式
The first line contains integer $m$ $(1<=m<=10^{5})$ — the number of discount types. The second line contains $m$ integers: $q_{1},q_{2},...,q_{m}$ $(1<=q_{i}<=10^{5})$ .
The third line contains integer $n$ $(1<=n<=10^{5})$ — the number of items Maxim needs. The fourth line contains $n$ integers: $a_{1},a_{2},...,a_{n}$ $(1<=a_{i}<=10^{4})$ — the items' prices.
The numbers in the lines are separated by single spaces.
The third line contains integer $n$ $(1<=n<=10^{5})$ — the number of items Maxim needs. The fourth line contains $n$ integers: $a_{1},a_{2},...,a_{n}$ $(1<=a_{i}<=10^{4})$ — the items' prices.
The numbers in the lines are separated by single spaces.
输出格式
In a single line print a single integer — the answer to the problem.
输入输出样例
输入 #1
1 2 4 50 50 100 100
输出 #1
200
输入 #2
2 2 3 5 50 50 50 50 50
输出 #2
150
输入 #3
1 1 7 1 1 1 1 1 1 1
输出 #3
3
In the first sample Maxim needs to buy two items that cost $100$ and get a discount for two free items that cost $50$ . In that case, Maxim is going to pay $200$ .
In the second sample the best strategy for Maxim is to buy $3$ items and get $2$ items for free using the discount. In that case, Maxim is going to pay $150$ .
In the second sample the best strategy for Maxim is to buy $3$ items and get $2$ items for free using the discount. In that case, Maxim is going to pay $150$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted