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.
(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 coin 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 removal ,the coin collection value goes to the previous value.Initially,with 0 coins ,coin collection value is 0.
Adding a Coin:on adding 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.
Ex1:
i/p1:10(deciding increment)
i/p2:0(selling coins)
i/p3:1(no of operations)
i/p4:{{0,5}}
o/p:10
Comments
Leave a comment