পৃষ্ঠাসমূহ

রবিবার, ১৮ জুন, ২০১৭

10114 Loansome Car Buyer

import java.util.*;

class Another {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        while (scanner.hasNext()) {
            int month = scanner.nextInt();
            if (month < 0) break;

            double[] rates = new double[month+1];
            double downPayment = scanner.nextDouble();
            double money = scanner.nextDouble();
            double currentOwe = money;

            double saved = money;
            int result = 0;

            int inputs = scanner.nextInt();
            for (int i=0;i<inputs;i++) {
                rates[scanner.nextInt()] = scanner.nextDouble();
            }
            double start = rates[0];
            money = money - (money*start) + (downPayment*(1-rates[0]));

            if (money > currentOwe) System.out.println("0 months");
            else {
                for (int i=1;i<=month;i++) {
                    if (rates[i] == 0) {
                        rates[i] = start;
                    } else {
                        start = rates[i];
                    }
                    currentOwe = currentOwe-(saved/month);
                    money = money - money*rates[i];

                    if (money > currentOwe) {
                        result = i;
                        break;
                    }
                }

                if (result == 1) {
                    System.out.println("1 month");
                } else {
                    System.out.println(result+" months");
                }
            }

        }
    }
}

কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন