coin collection
Rob is fond of collecting coins but unfortunately,sometimes he has to sell a coin to get other coins.he puts all his coins one over the other in a column.
There can be 2 types of Operations:
(0,i):Add coin with value i to the collection.
(1,0):sell a coin.
Selling a coin:
For selling a coin ,he picks up the top coiin in the coloumn if he constraint A is satisfied.Constraint A:Rob can only sell the coin if the coin collection value is more than Y.
Upon emoval ,the coin collection value goes to the previous value.Initially,with 0 coins ,coin collection value is 0.
Adding a Coin:
on addong a coin of value i to the collection the coin collection value increments via the following prodcedure.
If the coin collection had>=X value then current total value is X+i else X+2*i.
Rob needs to find and return the final value of coin collection after Q operations.
Note : Initially,the value X is 0 and not X.
Example1:
input1:10
input2:0
input3:1
input4:{{0,5}}
output:10
Comments
Leave a comment