GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Tuesday, 10 May 2022

Eating Queries Codeforces Solution | Codeforces Problem Solution 2022

E. Eating Queries
time limit per test
3.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Timur has n candies. The i-th candy has a quantity of sugar equal to ai. So, by eating the i-th candy, Timur consumes a quantity of sugar equal to ai.

Timur will ask you q queries regarding his candies. For the j-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 xj or print -1 if it's not possible to obtain such a quantity. In other words, you should print the minimum possible k such that after eating k candies, Timur consumes a quantity of sugar of at least xj or say that no possible k exists.

Solution Click Below:-  CLICK HERE

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).

Input

The first line of input contains a single integer t (1t1000)  — the number of test cases. The description of test cases follows.

The first line contains 2 integers n and q (1n,q1.5105) — the number of candies Timur has and the number of queries you have to print an answer for respectively.

Most Similar Words Codeforces Solution

The second line contains n integers a1,a2,,an (1ai104) — the quantity of sugar in each of the candies respectively.

Then q lines follow.

Each of the next q lines contains a single integer xj (1xj2109) – the quantity Timur wants to reach for the given query.

It is guaranteed that the sum of n and the sum of q over all test cases do not exceed 1.5105.

Output

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

Join Now for Solution:- 

No comments:

Post a Comment