Leonard and Pressure Game

All submissions for this problem are available.
Sheldon has invented a driving game which he wants to play with Leonard. Assume Sheldon has a very large cylinder that is open from the top. He fills this cylinder with $N$ type of liquids. Each liquid has some Density $Pi$ and covers $Hi$ height. All the liquids are immiscible and they will remain at the position where they are filled. The first liquid goes on the bottom and next liquid goes over it and so on. Now Sheldon will ask Leonard $Q$ rapidfire questions. In each question, Sheldon will give Leonard two values $L$ and $R$ and Leonard will have to calculate the total pressure considering only the liquids between height $L$ and $R$. That means if we remove all the liquid starting from height $L$ to $R$ and put it in some other Cylinder in the same order as they are in the present cylinder then what will be the pressure at the bottom of this new Cylinder. The total height of liquids will be the sum of the individual height of every liquid. You know Leonard is not very good intelligent so he asked you for help. You have to answer the $Q$ questions and output the total pressure in a new line. __The Formula for calculating Pressure is $P*g*H$__ $P$ = density $g$ = 10 (gravity) $H$ = height ###NOTE: The total pressure exerted at the bottom by all liquids is the sum of pressure exerted by every liquid individually. ###INPUT:  The first line contains integer $N$, the number of liquids.  Then next N lines contain $Pi$ and $Hi$. the density and the height covered by the liquid respectively.  Then the next line contains $Q$, the number of questions.  Next $Q$ lines contain the two Values $L$ and $R$ denoting the bottom and the top height.  ###OUTPUT:  For each query, Output an integer in a new line denoting the pressure at the bottom in the new cylinder.  ###Constraints:  $1 \leq N \leq 1000000$  $1 \leq Pi \leq 1000000$  $1 \leq Hi \leq 100$  $1 \leq Q \leq 100000$  $0$ $\leq$ $L$ $\leq$ $R$ $\leq$ Total Height  The sum of heights of all liquids $\leq$ $1000000$  ###SAMPLE INPUT: 3 6 2 5 6 4 3 5 1 11 2 6 4 9 0 11 1 1  ###SAMPLE OUTPUT: 480 200 240 540 0  ### Explanation: ###Query 1: $6*10*1$ (From height 1 to height 2) + $5*10*6$ (From height 2 to height 8) + $4*10*3$(From height 8 to height 11). ###Query 2: $5*10*4$ (From height 2 to height 6) ###Query 3: $5*10*4$ (From height 4 to height 8) + $4*10*1$ (From height 8 to height 9)Author:  p_unit 
Editorial  https://discuss.codechef.com/problems/COG1802 
Tags  codigo2k18, p_unit, simple 
Date Added:  20112018 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, COB, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions