A15256 | Promo
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
The store sells $n$ items, the price of the $i$ -th item is $p_i$ . The store's management is going to hold a promotion: if a customer purchases at least $x$ items, $y$ cheapest of them are free.
The management has not yet decided on the exact values of $x$ and $y$ . Therefore, they ask you to process $q$ queries: for the given values of $x$ and $y$ , determine the maximum total value of items received for free, if a customer makes one purchase.
Note that all queries are independent; they don't affect the store's stock.
The management has not yet decided on the exact values of $x$ and $y$ . Therefore, they ask you to process $q$ queries: for the given values of $x$ and $y$ , determine the maximum total value of items received for free, if a customer makes one purchase.
Note that all queries are independent; they don't affect the store's stock.
输入格式
The first line contains two integers $n$ and $q$ ( $1 \le n, q \le 2 \cdot 10^5$ ) — the number of items in the store and the number of queries, respectively.
The second line contains $n$ integers $p_1, p_2, \dots, p_n$ ( $1 \le p_i \le 10^6$ ), where $p_i$ — the price of the $i$ -th item.
The following $q$ lines contain two integers $x_i$ and $y_i$ each ( $1 \le y_i \le x_i \le n$ ) — the values of the parameters $x$ and $y$ in the $i$ -th query.
The second line contains $n$ integers $p_1, p_2, \dots, p_n$ ( $1 \le p_i \le 10^6$ ), where $p_i$ — the price of the $i$ -th item.
The following $q$ lines contain two integers $x_i$ and $y_i$ each ( $1 \le y_i \le x_i \le n$ ) — the values of the parameters $x$ and $y$ in the $i$ -th query.
输出格式
For each query, print a single integer — the maximum total value of items received for free for one purchase.
输入输出样例
输入 #1
5 3 5 3 1 5 2 3 2 1 1 5 3
输出 #1
8 5 6
In the first query, a customer can buy three items worth $5, 3, 5$ , the two cheapest of them are $3 + 5 = 8$ .
In the second query, a customer can buy two items worth $5$ and $5$ , the cheapest of them is $5$ .
In the third query, a customer has to buy all the items to receive the three cheapest of them for free; their total price is $1 + 2 + 3 = 6$ .
In the second query, a customer can buy two items worth $5$ and $5$ , the cheapest of them is $5$ .
In the third query, a customer has to buy all the items to receive the three cheapest of them for free; their total price is $1 + 2 + 3 = 6$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted