Game Saloon

View as PDF

Submit solution

Points: 1
Time limit: 1.0s
Memory limit: 256M

Problem types

A smart woman named BOB owns the only gaming saloon in ROSELAND. Customers have gaming-cards in which they store their gaming credits that they have bought prior to playing a game. To play, one must insert their gaming-card to the game machine, and their account is billed instantly at the end of every minute. If the card balance becomes non-positive, the game automatically turns off and the gaming-card is spit out. BOB’s saloon has two different pricing plans, the member-only plan and the one-time-visitor plan. The one-time-visitor plan is straight forward, it has a fixed price of \(p_1\) credits per minute. The member-only plan, on the other hand, is privileged, and it functions as follows: the first \(t_1\) minutes are priced at \(c_1\) credits per minute. The next \(t_2\) minutes cost \(c_2\) credits each. And all the following game time costs \(c_3\) credits per minute.

VANILLA has \(N\) credits on his account. He wants to play for \(K\) minutes and calculate how many credits will be left in his account after that time. If his credits are not enough to play for \(K\) minutes, he will want to know how many minutes he can play. If his account balance can’t afford even 1 minute of gameplay, the game won’t start.


The first line of the input is a character specifiying whether VANILLA is a member or a visitor. "\(M\)" shows that his plan is member-only plan and "\(V\)" shows that his plan is one-time-visitor plan. The next line either contains 7 integers (the member-only case) \(N, K, t_1, t_2, c_1, c_2, c_3\)OR it contains 3 integers (the one-time-visitor case) \(N, K, p_1\).


Print out just one integer, how many credits will be left after playing the game. In the case of insufficent funds print how many minutes can be played.



100 50 3




100 10 1 3 1 5 7




  • In the first example VANILLA wants to play 50 minutes but he can only play for 33 minutes.
  • In the second example VANILLA can play for 10 minutes and he is left with 42 credits.