CF1697B.Promo
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The store sells n items, the price of the i -th item is pi . 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 first line contains two integers n and q ( 1≤n,q≤2⋅105 ) — the number of items in the store and the number of queries, respectively.
The second line contains n integers p1,p2,…,pn ( 1≤pi≤106 ), where pi — the price of the i -th item.
The following q lines contain two integers xi and yi each ( 1≤yi≤xi≤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 .