Maximum litres of water that can be bought with N Rupees | PHP implementation of the above approach ; if buying glass bottles is profitable ; Glass bottles that can be bought ; Change budget according the bought bottles ; Plastic bottles that can be bought ; if only plastic bottles need to be bought ; Driver Code
< ? php function maxLitres ( $ budget , $ plastic , $ glass , $ refund ) { if ( $ glass - $ refund < $ plastic ) { $ ans = max ( ( int ) ( $ budget - $ refund ) / ( $ glass - $ refund ) , 0 ) ; $ budget -= $ ans * ( $ glass - $ refund ) ; $ ans += ( int ) ( $ budget / $ plastic ) ; echo $ ans . " STRNEWLINE " ; } else echo ( int ) ( $ budget / $ plastic ) . " STRNEWLINE " ; } $ budget = 10 ; $ plastic = 11 ; $ glass = 9 ; $ refund = 8 ; maxLitres ( $ budget , $ plastic , $ glass , $ refund ) ; ? >