object Solution { def howManyGames(price: Int, discount: Int, minPrice: Int, startAmount: Int): Int = { // Return the number of games you can buy @annotation.tailrec def loop(currentPrice: Int, currentAmount: Int, bought: Int): Int = { if(currentAmount < currentPrice) bought else { val newBought = bought + 1 val newCurrentPrice = if (currentPrice - discount >= minPrice) currentPrice - discount else minPrice loop(newCurrentPrice, currentAmount - currentPrice, newBought) } } loop(price, startAmount, 0) } def main(args: Array[String]) { val sc = new java.util.Scanner (System.in); var p = sc.nextInt(); var d = sc.nextInt(); var m = sc.nextInt(); var s = sc.nextInt(); val answer = howManyGames(p, d, m, s); println(answer) } }