You have just gotten back a test and, to your disappointment, you notice that you didn't do so well. However, you do know that your teacher is very nice and may only take your grades between a specific time period. You know you did a total of assignments , and you're curious about how your grades are. So, you ask your teacher for your grades over the entire semester, as well as how much each grade is worth.
Your teacher, being extremely generous, gives you a list of your grades in percentages, , as well as a list for how much the grade is worth overall in percentage, . It is guaranteed that the sum of all the percentages will add up to 100. These percentages can be between 0 and 100 inclusive. Can you code a program to answer queries ? Each query will ask for the percentage of your overall mark if only assignments between to (inclusive) are included. It is guaranteed that and the range is within .
Remember, to take your overall grade, you will multiply your grade (if it is 88%, put 88) by how much it is worth (if this is worth 30%, put 30) and add up all your assignments. Then, divide the total by your total percentage (if there are assignments with their percentages adding up to 50%, divide by 50) to get the percentage of your overall grade. Remember to times by 30 if the assignment is worth 30%, not 0.3 because this may result in a small difference from the answer when stored.
If a range is full of assignments that are not worth any marks, you will be given a since there is nothing to grade.
Input Specification
The first line of the input will contain integer and , representing the number of assignments you've completed and the number or queries respectively.
The next line will contain integers, where each integer represents your grade out of 100.
The following line will contain integers, representing the percentage value of each grade that goes towards your overall mark. The sum of all integers is guaranteed to be 100.
The next lines will contain integer and , the range of assignments that you want the overall mark for.
Output Specification
For each query, output the overall mark for the assignments between range L and R (inclusive). This mark should be an integer and rounded if it is a decimal.
Try using double instead of float.
Sample Input 1
10 8
80 80 90 90 100 100 30 10 0 100
10 10 7 3 5 0 5 0 30 30
0 9
0 4
5 9
0 0
9 9
2 4
5 6
5 5
Sample Output 1
62
86
48
80
100
93
30
100
Explanation
The first query lets us find the overall mark for all assignments. The sum of all your grades would be .
Then, we would divide by , which gives us . Since we round, we print .
The fourth query has one assignment, which would be since the assignment got a grade of 80%.
The last query has one assignment, which is not worth any marks. This will print out .
Sample Input 2
2 1
16 83
50 50
0 1
Sample Output 2
50
Explanation
The sum of the grades is . This adds up to . When divided by , we get , which rounds up to .
Comments