10114 - Loansome Car Buyer
Moderator: Board moderators
10114 - Loansome Car Buyer
For the second test case, why isn't the answer "0 months."? (At this time the buyer owes 12*500 = 6000 dollars, but has a car worth 9974.99 dollars.)
For the third test case, how can the answer be 49? After 49 months, the buyer still owes (60-49)*2400 = 26400 dollars, almost as much as the car was worth from the beginning, and more than it was worth even after one month?
I'm guessing there is some subtle sentence in the problem statement that I'm missing, and I'd be thankful if someone could help me out.
For the third test case, how can the answer be 49? After 49 months, the buyer still owes (60-49)*2400 = 26400 dollars, almost as much as the car was worth from the beginning, and more than it was worth even after one month?
I'm guessing there is some subtle sentence in the problem statement that I'm missing, and I'd be thankful if someone could help me out.
-
- Experienced poster
- Posts: 151
- Joined: Wed Aug 21, 2002 12:07 am
- Location: Seoul, Korea
- Contact:
It's a late reply but from the ranklist of the problem I see you not listed yet.
For the second test case, the total amount of loan is not 6000. $500 is the down payment, which were paid already, immediately after borrowing the money. The remaining loan to be paid is $9999.99 and it will be paid in 12 months. So your car's value is 9999.99 + 500 = 10499.99 and you owe 9999.99. The first depreciation in Month 0 causes the car to be 9974.9905 and that's still lesser than the loan.
But after the first month the car goes 9476.24 and you pay off 833.3325 so your remaining loan is 9166.66. So CAR > LOAN.![:)](./images/smilies/icon_smile.gif)
Hope I helped!![8)](./images/smilies/icon_cool.gif)
For the second test case, the total amount of loan is not 6000. $500 is the down payment, which were paid already, immediately after borrowing the money. The remaining loan to be paid is $9999.99 and it will be paid in 12 months. So your car's value is 9999.99 + 500 = 10499.99 and you owe 9999.99. The first depreciation in Month 0 causes the car to be 9974.9905 and that's still lesser than the loan.
But after the first month the car goes 9476.24 and you pay off 833.3325 so your remaining loan is 9166.66. So CAR > LOAN.
![:)](./images/smilies/icon_smile.gif)
Hope I helped!
![8)](./images/smilies/icon_cool.gif)
JongMan @ Yonsei
Re: 10114 - Loansome Car Buyer
Hi can anyone point me in the right direction, I'm not sure why i'm getting wrong answer? It passes on given test cases
Code: Select all
#include <fstream>
#include <map>
#include <iostream>
using namespace std;
int main()
{
// ifstream in("loan.in");
// ofstream out("loan.out");
int duration;
double deposit, amount, n_records;
int month;
while (cin >> duration >> deposit >> amount >> n_records) {
// cout << duration << " " << deposit << " " << amount << " " << n_records << endl;
if (duration < 0) break;
double repayment = amount / duration;
int mth, rcount = 0;
double rate, owed, car_worth = amount+deposit;
map<int, double> records;
for (int i = 0; i < n_records; ++i) {
cin >> mth >> rate;
// cout << mth << " " << rate << endl;
records[mth] = rate;
}
// cout << "r0: " << records[0] << endl;
mth = 0; rate = records[0];
//cout << duration << deposit << amount << n_records << endl;
for (int i = 0; i < duration; ++i) {
owed = amount-(repayment*(i));
if (owed < 0) break;
// cout << mth << endl;
if ((rcount < n_records)) {
// cout << "here" << endl;
// cout << i << endl;
// mth = i;
map<int,double>::iterator it = records.find(i);
if (it != records.end()) {
// cout << "here" << endl;
rate = it->second;
++rcount;
}
}
car_worth = car_worth - (car_worth*rate);
// cout << "month: " << i << " rate: " << rate << " car_worth: " << car_worth
// << " owed: " << owed << endl;
// cout << i << ": " << car_worth << endl;
if (owed < car_worth) {
month = i;
break;
}
// ++mth;
}
if (month > 1)
cout << month << " months" << endl;
else
cout << month << " month" << endl;
records.clear();
// cout << endl << endl;
}
return 0;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10114 - Loansome Car Buyer
Try input:AC output:
Code: Select all
100 0 75000 2
0 .10
99 .5
-1 0 0 0
Code: Select all
100 months
Check input and AC output for thousands of problems on uDebug!
Re: 10114 - Loansome Car Buyer
Whinii's post is helpful.
thank you
thank you
Re: 10114 - Loansome Car Buyer
hi guys
my code passed two testcases in problem and the one in here , but i'm still getting WA
my code passed two testcases in problem and the one in here , but i'm still getting WA
Code: Select all
#include <iostream>
#include <vector>
#include <iterator>
using namespace std ;
int main ()
{
freopen("in.txt", "r",stdin);
int duration;
cin>>duration;
vector< double > deprice;
while (duration >0)
{
int numchangedeprice;
double owed , val ,loan , price ;
cin>>loan>>price>>numchangedeprice;
owed =price;
val = price+loan ;
int j,i, a[100];
double b[100];
cin>>a[0]>>b[0];
for ( i=1 ; i<numchangedeprice ; i++)
{
cin>>a[i]>>b[i];
deprice.insert(deprice.end(),a[i]-a[i-1],b[i-1]);
}
deprice.insert(deprice.end(), duration -a[i-1]+1,b[i-1]);
int t;
double pay = price / duration;
for (t =0; t <duration ; t++)
{
owed -=pay;
val = val*(1-deprice[t]);
//pay = owed / duration;
if ( owed< val)
break;
}
if (t==0)
cout <<"1 month"<<endl;
else
cout << t+1<<" months"<<endl;
deprice.clear();
cin>>duration;
}
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10114 - Loansome Car Buyer
Don't read from a file. Try the I/O I posted above.
Check input and AC output for thousands of problems on uDebug!
Re: 10114 - Loansome Car Buyer
it passes the test that brainfry sent but still gives wrong answer
![:oops:](./images/smilies/icon_redface.gif)
![:(](./images/smilies/icon_frown.gif)
Code: Select all
#include <iostream>
#include <string>
#include <string.h>
#include <set>
#include <vector>
#include <stdio.h>
#include <map>
#include <stack>
#include <queue>
//#include <
#include <ctime>
#include <stdlib.h>
#include <search.h>
using namespace std ;
int main ()
{
//freopen("in.txt", "r",stdin);
//freopen("out.txt", "w", stdout);
int length, depricecnt;
double dpay,loan, a[110] , c[110];
int b[110];
cin>>length;
while (length >0)
{
cin>> dpay>> loan>> depricecnt;
memset(a, 0, sizeof a);
memset(b, 0, sizeof b);
memset(c, 0, sizeof c);
double value = dpay + loan , monthly = loan /length ;
for(int i =0 ; i<depricecnt;i++)
{
cin>>b[i];
cin>>a[i];
}
//fill c array
b[depricecnt] =length;
c[0] = a[0];
//int ii=0;
a[depricecnt]=a[depricecnt-1];
for(int i =1; i<=depricecnt; i++)
{
for(int t =b[i-1]; t <b[i]; t++)
c[t] = a[i-1];
}
c[length]=a[depricecnt-1];
/*for(int i=b[depricecnt-1]; i<length; i++)
c[i] =a[depricecnt-1];*/
value -= (c[0]*value);
int t =1;
for(t =1 ; t <length ; t++)
{
value -= (c[t]*value);
loan -= monthly;
if(loan <value)
break;
}
if (t ==1)
cout<<"1 month"<<endl;
else
cout<<t<<" months"<<endl;
cin>>length;
}
//cout<<double(CLOCKS_PER_SEC)/clock();
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10114 - Loansome Car Buyer
Input:AC output:
Code: Select all
100 74999 1 1
0 .20
-1 0 0 0
Code: Select all
0 months
Check input and AC output for thousands of problems on uDebug!
Re: 10114 - Loansome Car Buyer
thank u brain fry the problem was with that ,and one other that it should be exactly "0 months" not "0 month".
Re: 10114 - Loansome Car Buyer
Hi
my program answers are wrong but they are logical because i check them.
and one more thing i think that if 15000 drop 10% we get 13500 not 13950 why in the problem example, it said 13950 ?????
![:o](./images/smilies/icon_eek.gif)
my program answers are wrong but they are logical because i check them.
Code: Select all
#include<iostream>
using namespace std;
int main()
{
double month, down,loan,numd,d[200]={0};
while(cin>>month>>down>>loan>>numd)
{
int q;
for(int i=0;i<numd;i++)
{
cin>>q;
cin>>d[q];
}
double set;
for(int i=0;i<=month;i++)
{
if(d[i]==0)
d[i]=set;
else
set=d[i];
}
bool flag=true;
double owe=loan,worth=loan-(loan*d[0]);
int ans=0;
while(owe>worth)
{
ans++;
owe-=down;
worth=worth-(worth*d[ans]);
}
cout<<ans<<" months"<<endl;
}
}
![:o](./images/smilies/icon_eek.gif)
![:o](./images/smilies/icon_eek.gif)
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10114 - Loansome Car Buyer
The cars initial value is the down payment $500 plus the loan amount $15,000 = $15,500. As the buy drives it off the lot it depreciates to $15,500 * (1.0 - 0.1) = $13,950
Check input and AC output for thousands of problems on uDebug!
Re: 10114 - Loansome Car Buyer
I past the test case for 0 months, and all the test cases given in the problem statement, and I getting WA
Are there anymore critical test cases???
![:(](./images/smilies/icon_frown.gif)
Are there anymore critical test cases???
Re: 10114 - Loansome Car Buyer
hi, I didn't pass this test case. I want to know why, can you explain for me? thanks.brianfry713 wrote:Try input:AC output:Code: Select all
100 0 75000 2 0 .10 99 .5 -1 0 0 0
Code: Select all
100 months
I think during month 1 to 98, the depreciation is zero. and month 99 and 100, depreciation is 0.5. Right ? Wrong? and My program result for this testcase is 11 months.