Problem:


金利計算

金利は銀行に預けているお金に付き、その計算方法や利率は銀行によって様々です。利息と元金を合わせたものを元利と呼びますが、元利の計算方法として、利息を元金に組み入れずに計算する「単利」と利息を元金に組み入れて計算する「複利」というものがあり、より多くの元利を得るためにはこの差異を理解していなければなりません。元利の計算方法は以下のようになります。

銀行の数、お金を預ける年数、各銀行の情報（銀行番号、金利の種類、年利率（パーセント））を入力とし、最も元利が高くなる銀行番号を出力するプログラムを作成してください。ただし、最も元利が高くなる銀行は一つだけです。

入力

複数のデータセットが与えられます。入力の終わりはゼロひとつで示されます。各データセットは以下の形式で与えられます。

n
y
b1 r1 t1
b2 r2 t2
:
bn rn tn

1行目に銀行の数 n (1 ≤ n ≤ 50)、2行目にお金を預ける年数 y (1 ≤ y ≤ 30)が与えられます。続くn 行に i 番目の銀行の銀行番号 bi、年利率を表す整数 ri (1 ≤ ri ≤ 100)、 金利の種類 ti (1 または 2) が与えられます。金利の種類 ti は、単利の場合は1、複利の場合は2で与えられます。

データセットの数は 100 を超えません。

出力

データセットごとに、最も元利が高くなる銀行番号を１行に出力します。

入力例

2
8
1 5 2
2 6 1
2
9
1 5 2
2 6 1
0

出力例

2
1



Sample input:
2
8
1 5 2
2 6 1
2
9
1 5 2
2 6 1
0


Sample output:
2
1

Submission status: Wrong Answer

Solution code:
def ganri(y, b, r, t):
    if r == 1:
        return 1 * (1 + y * (r/100))
    else:
        return 1 * ((1 + (r/100)) ** y)

ans = []
while True:
    try:
        n = int(input())
        if (n == 0): raise
    except:
        print('\n'.join(ans))
        break


    y = int(input())
    results = []

    for i in range(1, n+1):
        results.append([i, ganri(y, *list(map(int, input().split())))])

    ans.append(max(results, key=lambda x: x[1])[0].__str__())

Submission status: Wrong Answer

Solution code:
def ganri(y, b, r, t):
    if r == 1:
        return (1 + y * (r/100))
    else:
        return ((1 + (r/100)) ** y)

ans = []
while True:
    try:
        n = int(input())
        if (n == 0): raise
    except:
        print('\n'.join(ans))
        break


    y = int(input())
    results = []

    for i in range(1, n+1):
        results.append([i, ganri(y, *list(map(int, input().split())))])

    ans.append(max(results, key=lambda x: x[1])[0].__str__())

Submission status: Wrong Answer

Solution code:
def ganri(y, b, r, t):
    if t == 1:
        return 1 + y * (r/100)
    else:
        return (1 + (r/100)) ** y

ans = []
while True:
    try:
        n = int(input())
        if (n == 0): raise
    except:
        print('\n'.join(ans))
        break


    y = int(input())
    results = []

    for i in range(1, n+1):
        results.append([i, ganri(y, *list(map(int, input().split())))])

    ans.append(max(results, key=lambda x: x[1])[0].__str__())

Submission status: Wrong Answer

Solution code:
def ganri(y, b, r, t):
    if t == 1:
        return 1 + y * (r/100)
    else:
        return (1 + (r/100)) ** y

ans = []
while True:
    try:
        n = int(input())
        if (n == 0): raise
    except:
        print('\n'.join(ans))
        print()
        break


    y = int(input())
    results = []

    for i in range(1, n+1):
        results.append([i, ganri(y, *list(map(int, input().split())))])

    ans.append(max(results, key=lambda x: x[1])[0].__str__())

Submission status: Accepted

Solution code:
from fractions import Fraction

n = input()
while n != 0:
    y = input()
    maxi = Fraction()
    maxi_num = 0
    
    while n > 0:
        n -= 1
        input_num = raw_input().split()
        b = int(input_num[0])
        r = int(input_num[1])
        t = int(input_num[2])
        
        money = None
        if t == 1:
            money = Fraction(100 + y * r, 100)
        else:
            money = Fraction(100 + r, 100) ** y
        if maxi < money:
            maxi = money
            maxi_num = b
    print maxi_num
    n = input()

Submission status: Accepted

Solution code:
while 1:
    n = int(input())
    if n == 0:break
    y = int(input())
    mv = 0
    for i in range(n):
        b,r,t = list(map(int,input().split()))
        if t == 1:
            spam = 1 + y*(r/100)
        else:
            spam = (1+(r/100))**y
        if spam > mv:
            result = b
            mv = spam

    print(result)

Submission status: Accepted

Solution code:
def simple_interest(r, y):
    return (100 + r * y) / 100
def compound_interest(r, y):
    return ((100 + r) / 100) ** y
import sys
import operator
f = sys.stdin

get_ganri = {1:simple_interest,2:compound_interest}
while True:
    n = int(f.readline())
    if n == 0:
        break
    y = int(f.readline())
    brt = [list(map(int, f.readline().split())) for _ in range(n)]
    b_ganri = [(b, get_ganri[t](r, y)) for b, r, t in brt]
    print(max(b_ganri, key=operator.itemgetter(1))[0])

Submission status: Accepted

Solution code:
while True:
    n = int(raw_input())
    if n == 0: break
    y = int(raw_input())
    res = []
    for i in range(n):
        b, r, t = map(int, raw_input().split())
        if t == 1:
            p = 1+y*(float(r)/100)
        else:
            p = (1+(float(r)/100))**y
        res.append((p, b))
    else:
        print sorted(res, reverse=True)[0][1]

Submission status: Accepted

Solution code:
#coding:UTF-8

import math

class Bank(object):
    #type: True complex, False simple
    def __init__(self, num, rate, type):
        self.num = num
        self.rate = rate
        self.type = type
    def calc(self, year):
        if(self.type):
            return (1 + self.rate / 100.0) ** year
        else:
            return (1 + year * self.rate / 100.0)

while True:
    n = input()
    if n == 0:
        break
    Bankarr = []
    gain = []
    y = input()
    for i in range(n):
        s = raw_input().split(" ")
        b = True if s[2] == "2" else False
        Bankarr.append(Bank(int(s[0]),float(s[1]), b))
    for i in range(n):
        gain.append(Bankarr[i].calc(y))
    bestgain = 0
    bestnum = 0
    for i in range(n):
        if bestgain < gain[i]:
            bestgain = gain[i]
            bestnum = Bankarr[i].num
    print "%d" % bestnum

Submission status: Accepted

Solution code:
def S(r,y):return 1+y*r/100
def C(r,y):return pow(1+r/100,y)
while 1:
    n=int(input())
    if n==0:break
    y=int(input())
    a=0.
    for _ in range(n):
        b,r,t=map(int,input().split())
        c=[S(r,y),C(r,y)][t-1]
        if(a<c): d=b;a=c
    print(d)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0: break
    y = int(input())
    dataset = {}
    for _ in range(n):
        b, r, t = map(int, input().split())
        dataset[b] = (1 + y * (r/100)) if t == 1 else pow((1 + r / 100), y)
    print(sorted(dataset.items(), key=lambda x: x[1])[-1][0])

Submission status: Accepted

Solution code:
# Aizu Problem 0240: Interest Rate

import sys, math, os, bisect

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def get_interest1(y, rate):
    return 100 + y * rate

def get_interest2(y, rate):
    return 100 * (1 + rate / 100)**y

while True:
    n = int(input())
    if n == 0:
        break
    y = int(input())
    high = 0
    for _ in range(n):
        no, rate, btype = [int(__) for __ in input().split()]
        if btype == 1:
            interest = get_interest1(y, rate)
        else:
            interest = get_interest2(y, rate)
        if interest > high:
            high = interest
            best = no
    print(best)

Submission status: Accepted

Solution code:
# AOJ 0240: Interest Rates
# Python3 2018.6.25 bal4u

while True:
	n = int(input())
	if n == 0: break	
	y = float(input())
	id, vmax = -1, 0
	for i in range(n):
		b, r, t = map(int, input().split())
		if t == 1: m = y*(r/100)+1
		else: m = (r/100+1)**y
		if id < 0 or m >= vmax: id, vmax = b, m
	print(id)

Submission status: Accepted

Solution code:
while 1:
    n = int(input())
    if n == 0:break
    y = int(input())
    b = [tuple(map(int, input().split())) for _ in range(n)]
    p = [((1 + b[i][1] / 100 * y) if b[i][2] == 1 else ((1 + b[i][1] / 100) ** y)) for i in range(n)]
    print(b[p.index(max(p))][0])

Submission status: Accepted

Solution code:
while True:
  n = int(input())
  if n == 0:
    break
  y = int(input())
  max_x = 0
  max_n = -1
  for _ in range(n):
    b, r, t = map(int, input().split())
    if t == 1:
      x = (1 + y * r / 100)
    else:
      x = (1 + r / 100) ** y
    if x > max_x:
      max_x = x
      max_n = b
  print(max_n)

Submission status: Accepted

Solution code:
def smpl(m,y,r):
    return m*(1+y*r/100.0)

def cmpnd(m,y,r):
    return m*pow((1+r/100.0),y)

while True:
    n=input()
    if n==0:break
    y=input()
    dic={}
    for i in range(n):
        b,r,t=map(int,raw_input().split())
        rate=smpl(10000,y,r) if t==1 else cmpnd(10000,y,r)
        dic[rate]=b
    print dic[max(dic)]

Submission status: Accepted

Solution code:
def simple(y, r):
    return (100 + y * r) / 100.0


def compound(y, r):
    return ((100 + r) / 100.0) ** y


while True:
    n = int(raw_input())
    if n == 0:
        break

    y = int(raw_input())

    m = (0, 0)

    for i in range(n):
        b, r, t = map(int, raw_input().split())
        if t == 1:
            interest = simple(y, r)
        else:
            interest = compound(y, r)

        if interest > m[1]:
            m = (b, interest)

    print m[0]

Submission status: Accepted

Solution code:
while 1:
	n=input()
	if n==0:break
	y=input()
	mx=0
	for i in range(n):
		b,r,t=map(int,raw_input().split())
		m=(1+y*float(r)/100) if t==1 else (1+float(r)/100)**y
		if m>mx:mx,a=m,b
	print a

Submission status: Accepted

Solution code:
while True:
    max_p = 0
    x = 0
    n = int(input())
    if n == 0:
        break
    y = int(input())
    l = [list(map(int,input().split())) for i in range(n)]

    for i in range(n):

        if l[i][2] == 1:
            p = 1 + ( y * l[i][1]/100)
        else:
            p = (1 + l[i][1]/100) ** y

        if p > max_p:
            max_p = p
            x = l[i][0]

    print(x)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    y = int(input())
    money = []
    for _ in range(n):
        a,b,c = map(int,input().split())
        if c == 1:
            money.append([1+b/100*y,a])
        else:
            money.append([(1+b/100)**y,a])
    money.sort(reverse = True)
    print(money[0][1])

Submission status: Accepted

Solution code:
while True:
    num = int(input())
    if num == 0:
        break
    y = int(input())
    rmax = 0
    bmax = None
    for _ in range(num):
        b, r, t = [int(x) for x in input().split()]
        if t == 1:
            val = 1 + r*y/100
        else:
            val = (1 + r/100)**y
        
        if val > rmax:
            bmax,rmax = b, val
    print(bmax)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n==0: break
    y = float(input())
    ans= 0 
    for i in range(n):
        b,r,t = map(int,input().split())
        if t==1:
            m = 1+y*(r/100)
        else:
            m = (1+(r/100))**y
        
        if ans < m:
            ans = m
            a = b
    
    print(a)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0: break  
    y = float(input())
    id, vmax = -1, 0
    for i in range(n):
        b, r, t = map(int, input().split())
        if t == 1: m = y*(r/100)+1
        else: m = (r/100+1)**y
        if id < 0 or m >= vmax: id, vmax = b, m
    print(id)

Submission status: Accepted

Solution code:
# AOJ 0240: Interest Rates
# Python3 2018.6.25 bal4u
 
while True:
    n = int(input())
    if n == 0: break   
    y = float(input())
    id, vmax = -1, 0
    for i in range(n):
        b, r, t = map(int, input().split())
        if t == 1: m = y*(r/100)+1
        else: m = (r/100+1)**y
        if id < 0 or m >= vmax: id, vmax = b, m
    print(id)

Submission status: Accepted

Solution code:
while 1:
    N = int(input())
    if N == 0:
        break
    y = int(input())
    v = 0; k = None
    for i in range(N):
        b, r, t = map(int, input().split())
        if t == 1:
            w = 1 + y * r /100
        else:
            w = (1 + r / 100) ** y
        if v < w:
            v = w
            k = b
    print(k)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Interest Rates
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0240

"""
import sys


def solve(y, banks):
    return sorted([(1 + r * y / 100, b) if t == 1 else ((1 + r / 100) ** y, b) for b, r, t in banks])[-1][-1]


def main(args):
    while True:
        n = int(input())
        if n == 0:
            break
        y = int(input())
        banks = [(int(i) for i in input().split()) for _ in range(n)]
        ans = solve(y, banks)
        print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

while True:
    n = int(input())
    if n == 0:
        break
    y = int(input())
    b = -1
    maxMoney = -1
    ans = -1
    for l in range(n):
        b,r,t = [float(i) for i in input().split()]
        money = -1
        if t == 1:
            money = 1.0 + y * r / 100.0
        else:
            money = (1.0 + (r / 100.0))**y
        if maxMoney < money:
            maxMoney = money
            ans = int(b)
        #print(money)
            
    print(ans)

Submission status: Accepted

Solution code:
while 1:
    n=int(input())
    if n==0:break
    y=int(input())
    bank_list=[]
    max_m=0
    num_keep=0
    mo=0
    for i in range(n):
        bank_list.append(list(map(int,input().split())))
    for i in bank_list:
        if i[2]==1:
            mo=1+y*i[1]/100
        if i[2]==2:
            mo=(1+(i[1]/100))**y
        if mo>max_m:
            max_m=mo
            num_keep=i[0]
    print(num_keep)

Submission status: Accepted

Solution code:
while 1:
    n = int(input())
    if n == 0:
        break

    y = int(input())
    ans = 0
    num = 0
    for _ in range(n):
        b, r, t = map(int, input().split())
        if t == 1:
            tmp = 1 + y * (r / 100)
        else:
            tmp = pow((1 + r / 100), y)

        if tmp > ans:
            ans = tmp
            num = b

    print(num)