Close
Topic list
Ravi and Coins
MEDIUM
30 mins
Other topics
Problem solved
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

# Ravi and Coins

Contributed by
Jaypal Mudaliyar
Medium
0/80
Avg time to solve 30 mins
Success Rate 60 %
Share

## Problem Statement

#### Now Ravi has found the answers to the questions but is not sure if they are completely correct, So he has asked you to calculate the answers to these questions. Can you help him?.

##### EXAMPLE :
``````Input: ‘N’ = 3, ‘M' = 2, ‘Q’ = 1, ‘ARR’ = [[0, 1], [0, 2]], ‘QUERIES’ = [2]

Output: 2
In this case,
After Day 1 number of coins in the boxes will be: [1, 1, 0]
After Day 2 number of coins in the boxes will be: [2, 2, 1]
Hence the boxes having at least ‘2’ coins are Box 0 and Box 1.
``````
Detailed explanation ( Input/output format, Notes, Constraints, Images )
##### Sample Input 1 :
``````2
5 1 1
1 4
1
7 3 2
0 3
2 6
4 6
0
2
``````
##### Sample Output 1 :
``````4
7 5
``````
##### Explanation Of Sample Input 1 :
``````For the first test case,
After Day 1 number of coins in the boxes will be: [0, 1, 1, 1, 1]
Hence the boxes having at least ‘1’ coin are Box 1, 2, 3, and 4.

Hence, the output will be: 4

For the second test case,
After Day 1 number of coins in the boxes will be: [1, 1, 1, 1, 0, 0, 0]
After Day 2 number of coins in the boxes will be: [1, 1, 2, 2, 1, 1, 1]
After Day 3 number of coins in the boxes will be: [1, 1, 2, 2, 2, 2, 2]
All the boxes have at least a ‘1’ coin, hence the answer to the ‘1’st question is ‘7’.
The boxes having at least ‘2’ coins are Box 2, 3, 4, 5, and 6.

Hence, the output will be: 7 5
``````
##### Sample Input 2 :
``````2
10 3 3
5 9
3 7
2 6
3
0
0
8 4 5
0 0
5 5
4 4
7 7
2
0
4
3
0
``````
##### Sample Output 2 :
``````2 10 10
0 8 0 0 8
``````
Auto
Console