SGIFT - Sabbir and gifts
Sabbir is a little boy. he went to a gift shop with his mother. There were n different types of gifts in the shop. All the gifts were attractive to Sabbir. He wanted to buy all the gifts which are in price range a <= p <= b. You are given prices of all the gifts and a, b. Sabbir's mother need your help. Please calculate the total amount of price of all gifts of that range for Sabbir's mother.
Input
In the first line there will be n, the number of gifts in the shop.
In the next line there will be n integers p1, p2, p3 ... pn denoting price of every gift.
In the third line there will be Q, the number of queries.
The next Q lines contain two integers a and b.
Constraints
1 <= n <= 105.
1 <= pi <= 109.
1 <= Q <= 105.
1 <= a, b <= 109.
Output
Print Q lines. Every line contains one integer, sum of all prices for that range given in the query.
Example
Input: 7 1 3 2 1 5 2 2 4 1 2 1 5 3 5 4 5 Output: 8 16 8 5
NOTE: for first query, Sabbir will buy all the gifts of prices 1, 2, 1, 2, 2. So, sum is 8.
For second query, Sabbir will buy all the gifts, so the sum is 16.
hide comments
itissabbir:
2017-02-27 17:46:28
@aman224 I have fixed the time limit for JAVA . Last edit: 2017-02-27 23:23:22 |
|
aman224:
2017-02-27 10:17:34
Time limit is too strict for JAVA :(
|
|
itissabbir:
2017-02-27 04:46:22
@[Rampage] Blue.Mary , I am so sorry . there was a mistake uploading the test data file . please try submitting again. again sorry for the inconvenience. |
|
[Rampage] Blue.Mary:
2017-02-27 03:28:09
Are you sure your test cases are right? |
Added by: | sabbir |
Date: | 2017-02-26 |
Time limit: | 0.400s-0.800s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All |