10114 - Loansome Car Buyer

All about problems in Volume 101. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Per
A great helper
Posts: 429
Joined: Fri Nov 29, 2002 11:27 pm
Location: Sweden

10114 - Loansome Car Buyer

Post by Per » Wed Jul 16, 2003 11:30 pm

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.

Whinii F.
Experienced poster
Posts: 151
Joined: Wed Aug 21, 2002 12:07 am
Location: Seoul, Korea
Contact:

Post by Whinii F. » Sat Aug 09, 2003 4:28 pm

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. :)

Hope I helped! 8)
JongMan @ Yonsei

Per
A great helper
Posts: 429
Joined: Fri Nov 29, 2002 11:27 pm
Location: Sweden

Post by Per » Sun Aug 10, 2003 3:46 pm

Ah, I had completely misunderstood the meaning of the downpayment! :oops:

Thanks a lot!

bonsu
New poster
Posts: 3
Joined: Fri May 24, 2013 5:55 pm

Re: 10114 - Loansome Car Buyer

Post by bonsu » Tue Jun 04, 2013 3:31 pm

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;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10114 - Loansome Car Buyer

Post by brianfry713 » Tue Jun 11, 2013 3:58 am

Try input:

Code: Select all

100 0 75000 2
0 .10
99 .5
-1 0 0 0
AC output:

Code: Select all

100 months
Check input and AC output for thousands of problems on uDebug!

jiayeli
New poster
Posts: 1
Joined: Tue Jul 30, 2013 8:13 pm

Re: 10114 - Loansome Car Buyer

Post by jiayeli » Tue Jul 30, 2013 8:19 pm

Whinii's post is helpful.
thank you

fazel
New poster
Posts: 6
Joined: Fri Aug 02, 2013 4:44 am

Re: 10114 - Loansome Car Buyer

Post by fazel » Fri Aug 02, 2013 6:17 am

hi guys

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;
	}
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10114 - Loansome Car Buyer

Post by brianfry713 » Sat Aug 03, 2013 1:17 am

Don't read from a file. Try the I/O I posted above.
Check input and AC output for thousands of problems on uDebug!

fazel
New poster
Posts: 6
Joined: Fri Aug 02, 2013 4:44 am

Re: 10114 - Loansome Car Buyer

Post by fazel » Mon Sep 09, 2013 3:32 pm

it passes the test that brainfry sent but still gives wrong answer :oops: :(

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();
	
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10114 - Loansome Car Buyer

Post by brianfry713 » Tue Sep 10, 2013 12:27 am

Input:

Code: Select all

100 74999 1 1
0 .20
-1 0 0 0
AC output:

Code: Select all

0 months
Check input and AC output for thousands of problems on uDebug!

fazel
New poster
Posts: 6
Joined: Fri Aug 02, 2013 4:44 am

Re: 10114 - Loansome Car Buyer

Post by fazel » Tue Sep 10, 2013 10:36 pm

thank u brain fry the problem was with that ,and one other that it should be exactly "0 months" not "0 month".

f.maru
New poster
Posts: 13
Joined: Wed Jul 31, 2013 2:27 pm

Re: 10114 - Loansome Car Buyer

Post by f.maru » Fri Oct 04, 2013 1:29 pm

Hi
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;
          }
          
}
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 :o

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10114 - Loansome Car Buyer

Post by brianfry713 » Tue Oct 08, 2013 3:10 am

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!

lmky
New poster
Posts: 1
Joined: Tue Oct 15, 2013 3:00 am

Re: 10114 - Loansome Car Buyer

Post by lmky » Tue Oct 15, 2013 3:06 am

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???

ccsnail
New poster
Posts: 1
Joined: Sat Dec 07, 2013 3:40 pm

Re: 10114 - Loansome Car Buyer

Post by ccsnail » Sat Dec 07, 2013 3:53 pm

brianfry713 wrote:Try input:

Code: Select all

100 0 75000 2
0 .10
99 .5
-1 0 0 0
AC output:

Code: Select all

100 months
hi, I didn't pass this test case. I want to know why, can you explain for me? thanks.
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.

Post Reply

Return to “Volume 101 (10100-10199)”