DEPOSIT - Deposit

Banks offer deposit schemes of various kinds to attract customers. In an r -year progressively reducing recurring deposit scheme (PRRDS) of a bank, a customer is required to deposit progressively reducing amounts every year for r years. Depending on the duration r of the scheme and the total amount T deposited in r years, the bank offers to return on maturity, i.e., after the expiry of r years, an amount R , which is equal to k times the amount deposited in the first year. The bank ensures that the return R looks attractive by making a suitable choice of k ; k being a natural number.

In a PRRDS, the amount to be deposited in each but the last two years is exactly equal to the sum of amounts to be deposited in the next two years. The amounts to be deposited in the last two years, say x in the last year and y in the last but one year, are progressively reducing (x, y > 0;y > x) and are determined so that the total amount deposited in r years is exactly equal to the specified amount T . Assume that all deposits are in whole number of Rupees.

Write a program for the bank, so that given r , k and T , the program computes x and y for which the return R is maximum. For example in a 4-year scheme with r = 4 , k = 3 and T = 500 , the progressively reducing recurring deposits 248, 126, 122 and 4, ensures the maximum return R = 744 with x = 4 and y = 122 .


The input may contain multiple test cases.

For each test case there is only one input line. The line gives values of r , k and T . Assume that r is not greater than 20.

A line containing a zero `0' as the first character follows the last case.


For each test case there is only one output line. The line gives the computed values of x , y and R .


4 3 500 
5 3 10000 
6 4 8000 
8 5 12000 

4 122 744 
5 1425 12855 
1 666 13332 
1 363 23635

hide comments
Sigma Kappa: 2020-04-24 02:21:12

One should add also so that it is always r >= 2 and x should be minimized, in case of a tie.

Last edit: 2020-04-24 10:57:30
holmesherlock: 2017-12-23 09:00:21

good logical problem

arjun: 2014-07-31 15:51:53

edit: Don't post answers

Last edit: 2014-12-08 17:39:38
nitesh kumar: 2014-05-11 21:39:33

wats the limit of T??
my algo heavily depends on it,,gettin tle verdict..

Last edit: 2014-05-11 21:40:16
Momontho Mashak Monmoy: 2012-08-08 09:25:09

After plenty of WA, in case of tie in R, I minimized x & then got AC, this requirement should've been stated in the problem statement .

aman garg: 2012-06-22 17:37:25

Can anyone please help me.I am getting wrong answer continuously.code id :7196103

Romal Thoppilan: 2011-08-23 21:41:21

What to do in cases where ,
r = 3 years.
(x,y) could take many values .
H E L P !!

Last edit: 2011-08-23 22:02:30
Nathaniel Barshay: 2010-08-10 04:51:58

Note that 64-bit integers are necessary and sufficient

Harsh: 2010-06-15 08:31:09

What should be the output when no such x,y values are poosible for given T and r

Seshadri R: 2010-05-04 07:01:10

SPOJ server seems to have a clock that runs both forward and backward in time. This problem is posted on 2008-12-09 but there are comments on 2009-02-17, 2009-07-04 and 2009-07-07. Probably, these are from those who have the privilege to have a preview before the problem is released for all SPOJ registrants?

Added by:Jimmy
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO NODEJS PERL6 VB.NET
Resource:ACM Kanpur 2007