Submit | All submissions | Best solutions | Back to list |
EIAPP24252FQ4 - Buying Car |
In the United States, cars are often purchased through financing. When buying a car, a customer makes an initial down payment, and the remaining cost is financed through a loan. The loan is repaid over a fixed number of months with a fixed monthly payment that includes both principal and interest.
Additionally, cars lose value over time. The moment a car is purchased, its value immediately drops to 90% of its original price. After that, it continues to depreciate by a fixed percentage each month.
You own an old car and want to buy a new one. Given the financial conditions of both the old and new cars, determine the minimum number of months required before you can sell the old car, pay off the remaining loan, and afford the down payment for the new car without needing extra money.
For example,
- Old car price: $50,000
- Down payment: 20% of $50,000 = $10,000
- Loan term: 60 months
- Annual interest rate: 4.8% → Monthly interest rate: 0.4%
- Monthly depreciation rate: 1.67%
- New car price: $50,000
After 45 months, the car is worth $21,090. At this point:
- Remaining loan balance is $10,954
- You can pay the loan off and still have enough for the $10,000 down payment on the new car.
Input
You will be given:
- P - Initial price of the old car (dollars)
- New_P - Price of the new car (dollars)
- m - Down payment percentage (0 < m < 100)
- n - Loan term in months
- R - Annual interest rate (percentage)
- L - Monthly depreciation rate (percentage)
Output
Print the minimum number of months required before you can sell the old car, pay off the remaining loan balance, and make the down payment for the new car without requiring additional money. If customer cannot make a down payment for the new car after the period of given months, print the amount of additional money.
Sample
Added by: | Ha Minh Ngoc |
Date: | 2025-05-22 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | CSHARP C++ 4.3.2 CPP CPP14 CPP14-CLANG FSHARP GO JAVA JS-MONKEY NODEJS PHP PYTHON PYPY PYPY3 PYTHON3 RUBY SQLITE SWIFT VB.NET |