Friday, 28 November 2014

UVa 10114 - Loansome Car Buyer Solution (HDU 1309, ZOJ 1706, POJ 1571, UVALive 5332, Regionals 1999 >> North America - Mid-Central USA)

///     Raihan Ruhin
///     CSE, Jahangirnagar University.
///     Dhaka-Bangladesh.
///     id: raihanruhin (topcoder / codeforces / codechef / hackerrank / uva / uvalive, spoj), 3235 (lightoj)
///     mail: raihanruhin@ (yahoo / gmail / facebook)
///     blog: ruhinraihan.blogspot.com

#include<bits/stdc++.h>
using namespace std;

#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define PI acos(-1.0)

#define MOD 1000000007
#define MX 100010


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    double tmonth, downPay, price, interest[105], owe;
    int k, m;

    while(cin>>tmonth>>downPay>>price>>k && tmonth>=0)
    {
        owe=price;
        double monthlyPay=price/(double) tmonth;
        price+=downPay;
        for(int i=0;i<=tmonth;i++) interest[i]=-1;
        for(int i=0;i<k;i++)
        {
            cin>>m;
            cin>>interest[m];
        }
        for(int i=1;i<=tmonth;i++)
            if(interest[i]==-1) interest[i]=interest[i-1];

        int ans=-1;

        int i=0;
        while(ans==-1)
        {
            price=price-price*interest[i];
            if(price>owe) ans=i;
            owe-=monthlyPay;
            i++;
            //cout<<interest[i]<<endl;
        }
        cout<<ans<<" month";
        if(ans!=1) cout<<"s";
        cout<<"\n";
    }
return 0;
}

No comments:

Post a Comment