CF1697B.Promo

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

The store sells nn items, the price of the ii-th item is pip_i. The store's management is going to hold a promotion: if a customer purchases at least xx items, yy cheapest of them are free.

The management has not yet decided on the exact values of xx and yy. Therefore, they ask you to process qq queries: for the given values of xx and yy, 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.

商店出售 nn 种商品,第 ii 种商品的价格为 pip_i。商店管理层计划开展一项促销活动:若顾客一次购买至少 xx 件商品,则其中最便宜的 yy 件免费。

目前管理层尚未确定 xx 和 yy 的具体取值。因此,他们请你处理 qq 个查询:对每个给定的 xx 和 yy,求出顾客一次购物所能获得的免费商品总价值的最大值。

注意:所有查询相互独立,不会影响商店的库存。

输入格式

The first line contains two integers nn and qq (1≤n,q≤2⋅1051 \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 nn integers p1,p2,…,pnp_1, p_2, \dots, p_n (1≤pi≤1061 \le p_i \le 10^6), where pip_i — the price of the ii-th item.

The following qq lines contain two integers xix_i and yiy_i each (1≤yi≤xi≤n1 \le y_i \le x_i \le n) — the values of the parameters xx and yy in the ii-th query.

第一行包含两个整数 nn 和 qq(1≤n,q≤2⋅1051 \le n, q \le 2 \cdot 10^5)—— 分别表示商店中商品的数量和查询的数量。

第二行包含 nn 个整数 p1,p2,…,pnp_1, p_2, \dots, p_n(1≤pi≤1061 \le p_i \le 10^6),其中 pip_i 表示第 ii 个商品的价格。

接下来的 qq 行每行包含两个整数 xix_i 和 yiy_i(1≤yi≤xi≤n1 \le y_i \le x_i \le n)—— 表示第 ii 次查询中的参数 xx 和 yy 的值。

输出格式

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,55, 3, 5, the two cheapest of them are 3+5=83 + 5 = 8.

In the second query, a customer can buy two items worth 55 and 55, the cheapest of them is 55.

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=61 + 2 + 3 = 6.

在第一次查询中,顾客可以购买三件价格分别为 55、33、55 的商品,其中最便宜的两件价格之和为 3+5=83 + 5 = 8。

在第二次查询中,顾客可以购买两件价格均为 55 的商品,其中最便宜的一件价格为 55。

在第三次查询中,顾客必须购买所有商品,才能免费获得其中最便宜的三件;这三件商品的总价为 1+2+3=61 + 2 + 3 = 6。

输入解题思路,AI测评打分。不知道怎么写?

首页