CF1676E.Eating Queries

普及-

通过率:0%

时间限制:3.50s

内存限制:256MB

AC君温馨提醒

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

题目描述

Timur has nn candies. The ii-th candy has a quantity of sugar equal to aia_i. So, by eating the ii-th candy, Timur consumes a quantity of sugar equal to aia_i.

Timur will ask you qq queries regarding his candies. For the jj-th query you have to answer what is the minimum number of candies he needs to eat in order to reach a quantity of sugar greater than or equal to xjx_j or print -1 if it's not possible to obtain such a quantity. In other words, you should print the minimum possible kk such that after eating kk candies, Timur consumes a quantity of sugar of at least xjx_j or say that no possible kk exists.

Note that he can't eat the same candy twice and queries are independent of each other (Timur can use the same candy in different queries).

蒂穆尔有 nn 颗糖果。第 ii 颗糖果含糖量为 aia_i。因此,吃掉第 ii 颗糖果会使蒂穆尔摄入 aia_i 单位的糖。

蒂穆尔将向你提出 qq 个关于这些糖果的查询。对于第 jj 个查询,你需要回答:他至少需要吃掉多少颗糖果,才能使总摄入糖量大于等于 xjx_j;若无法达到该糖量,则输出 -1。换言之,你需要找出最小的可能值 kk,使得吃掉 kk 颗糖果后,蒂穆尔摄入的总糖量至少为 xjx_j;若不存在这样的 kk,则说明无法实现。

注意:每颗糖果最多只能吃一次;且各查询相互独立(即蒂穆尔可在不同查询中重复使用同一颗糖果)。

输入格式

The first line of input contains a single integer tt (1≤t≤10001 \leq t \leq 1000) — the number of test cases. The description of test cases follows.

The first line contains 22 integers nn and qq (1≤n,q≤1.5⋅1051 \leq n, q \leq 1.5\cdot10^5) — the number of candies Timur has and the number of queries you have to print an answer for respectively.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1041 \leq a_i \leq 10^4) — the quantity of sugar in each of the candies respectively.

Then qq lines follow.

Each of the next qq lines contains a single integer xjx_j (1≤xj≤2⋅1091 \leq x_j \leq 2 \cdot 10^9) – the quantity Timur wants to reach for the given query.

It is guaranteed that the sum of nn and the sum of qq over all test cases do not exceed 1.5⋅1051.5 \cdot 10^5.

输入的第一行包含一个整数 tt(1≤t≤10001 \leq t \leq 1000),表示测试用例的数量。随后是各测试用例的描述。

第一行包含两个整数 nn 和 qq(1≤n,q≤1.5⋅1051 \leq n, q \leq 1.5\cdot10^5),分别表示 Timur 拥有的糖果数量以及你需要回答的查询数量。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1041 \leq a_i \leq 10^4),分别表示每颗糖果所含的糖量。

接下来是 qq 行。

接下来的 qq 行中,每行包含一个整数 xjx_j(1≤xj≤2⋅1091 \leq x_j \leq 2 \cdot 10^9),表示当前查询中 Timur 希望达到的糖量总和。

保证所有测试用例中 nn 的总和与 qq 的总和均不超过 1.5⋅1051.5 \cdot 10^5。

输出格式

For each test case output qq lines. For the jj-th line output the number of candies Timur needs to eat in order to reach a quantity of sugar greater than or equal to xjx_j or print -1 if it's not possible to obtain such a quantity.

对于每个测试用例,输出 qq 行。第 jj 行输出 Timur 需要吃的糖果数量,使得其摄入的糖分总量大于等于 xjx_j;若无法达到该糖分总量,则输出 -1。

输入输出样例

  • 输入#1

    3
    8 7
    4 3 3 1 1 4 5 9
    1
    10
    50
    14
    15
    22
    30
    4 1
    1 2 3 4
    3
    1 2
    5
    4
    6

    输出#1

    1
    2
    -1
    2
    3
    4
    8
    1
    1
    -1

说明/提示

For the first test case:

For the first query, Timur can eat any candy, and he will reach the desired quantity.

For the second query, Timur can reach a quantity of at least 1010 by eating the 77-th and the 88-th candies, thus consuming a quantity of sugar equal to 1414.

For the third query, there is no possible answer.

For the fourth query, Timur can reach a quantity of at least 1414 by eating the 77-th and the 88-th candies, thus consuming a quantity of sugar equal to 1414.

For the second test case:

For the only query of the second test case, we can choose the third candy from which Timur receives exactly 33 sugar. It's also possible to obtain the same answer by choosing the fourth candy.

对于第一个测试用例:

对于第一个查询,Timur 可以吃任意一颗糖果,即可达到目标糖分量。

对于第二个查询,Timur 可通过吃第 7 颗和第 8 颗糖果,使摄入的糖分总量至少达到 1010,此时消耗的糖分总量为 1414。

对于第三个查询,不存在可行解。

对于第四个查询,Timur 可通过吃第 7 颗和第 8 颗糖果,使摄入的糖分总量至少达到 1414,此时消耗的糖分总量为 1414。

对于第二个测试用例:

对于第二个测试用例中唯一的查询,我们可以选择第三颗糖果,Timur 将恰好获得 33 单位糖分。同样地,选择第四颗糖果也可得到相同答案。

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

首页