Array ( [0] => [1] => questions [2] => Basic [3] => Counting-Rock-Samples )
Juan Marquinho is a geologist and he needs to count rock samples in order to send it to a chemical laboratory. He has a problem: The laboratory only accepts rock samples by a range of its size in ppm (parts per million).
Juan Marquinho receives the rock samples one by one and he classifies the rock samples according to the range of the laboratory. This process is very hard because the number of rock samples may be in millions.
Juan Marquinho needs your help, your task is to develop a program to get the number of rocks in each of the ranges accepted by the laboratory.
An positive integer S (the number of rock samples) separated by a blank space, and a positive integer R (the number of ranges of the laboratory); A list of the sizes of S samples (in ppm), as positive integers separated by space R lines where the ith line containing two positive integers, space separated, indicating the minimum size and maximum size respectively of the ith range.
Constraints:
10 <= S <= 10000
1 <= R <= 1000000
1<=size of Sample <= 1000
R lines where the ith line contains a single non-negative integer indicating the number of the samples which lie in the ith range.
10 2 345 604 321 433 704 470 808 718 517 811 300 350 400 700
2 4
20 3 921 107 270 631 926 543 589 520 595 93 873 424 759 537 458 614 725 842 575 195 1 100 50 600 1 1000
1 12 20
10 3 100 150 163 245 125 302 888 451 200 555 50 250 300 500 300 900
6 2 4
Login to see Discussion
here we are just following what is given in the question
first we are reading the required input
then we take the first range , traverse the entire array and check for stones which are in the given range and keep incrementing the count when rocks are found
we follow this step till all the ranges are finished and print the output
Note :
Let us know if you can come up with a better approach, mail us at support@theinquisitive.in Your approach will be reviewed and posted with credits to you.
Login to see Solution