Vegetable Market
Practice
3.9 (8 votes)
Basic programming
Basics of implementation
Data structures
Hash maps
Hash tables
Implementation
Medium
Problem
75% Success 17743 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

There are \(N\) stalls in a vegetable market that are selling vegetables. You have to buy an equal amount of vegetables from each stall. If a stall does not have enough vegetables to offer, then you have to buy all the vegetables available in that stall. If you are given the number of vegetables that every stall can offer, determine the minimum quantity that you need to buy from each stall such that you have at least \(K\) vegetables in total.

Input format

  • First line: Integer \(N\) denoting the number of stalls
  • Next line: \(N\) space-separated integers and \(quan_{i}\) denoting the \(i^{th}\) integer which determines the quantity of vegetables that \(i^{th}\) stall would be offering
  • Next line: Integer \(Q\) denoting the number of queries
  • Next \(Q\) lines: Integer \(K_{i}\) denoting the minimum amount of vegetables needed in total

Output format

  • For each query, print the minimum quantity of vegetables that you have to buy from each shop in a new line. Print \(-1\) if it is not possible to buy the required number of vegetables.

Constraints

\(1 \leq N \leq 10^5\)

\(1 \leq quan_{i} \leq 10^6\)

\(1 \leq Q \leq 10^{5}\)

\(1 \leq K_{i} \leq 10^{11}\)

 

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
6 votes
Tags:
AlgorithmsBasic ProgrammingBasics of ImplementationImplementationMedium
Points:30
17 votes
Tags:
Basic ProgrammingImplementationMedium
Points:30
7 votes
Tags:
Basic ProgrammingBasics of ImplementationImplementationMediumadhoc