Problem:


Score: 400 points

Problem Statement

To become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives.

He is famous across the country for his ability to foresee the future. He already knows that the price of one stock in the next N days will be as follows:

A_1 yen on the 1-st day, A_2 yen on the 2-nd day, ..., A_N yen on the N-th day.

In the i-th day, M-kun can make the following trade any number of times (possibly zero), within the amount of money and stocks that he has at the time.

Buy stock: Pay A_i yen and receive one stock.

Sell stock: Sell one stock for A_i yen.

What is the maximum possible amount of money that M-kun can have in the end by trading optimally?

Constraints

2 \leq N \leq 80

100 \leq A_i \leq 200

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \cdots A_N

Output

Print the maximum possible amount of money that M-kun can have in the end, as an integer.

Sample Input 1

7
100 130 130 130 115 115 150

Sample Output 1

1685

In this sample input, M-kun has seven days of trading. One way to have 1685 yen in the end is as follows:

Initially, he has 1000 yen and no stocks.

Day 1: Buy 10 stocks for 1000 yen. Now he has 0 yen.

Day 2: Sell 7 stocks for 910 yen. Now he has 910 yen.

Day 3: Sell 3 stocks for 390 yen. Now he has 1300 yen.

Day 4: Do nothing.

Day 5: Buy 1 stock for 115 yen. Now he has 1185 yen.

Day 6: Buy 10 stocks for 1150 yen. Now he has 35 yen.

Day 7: Sell 11 stocks for 1650 yen. Now he has 1685 yen.

There is no way to have 1686 yen or more in the end, so the answer is 1685.

Sample Input 2

6
200 180 160 140 120 100

Sample Output 2

1000

In this sample input, it is optimal to do nothing throughout the six days, after which we will have 1000 yen.

Sample Input 3

2
157 193

Sample Output 3

1216

In this sample input, it is optimal to buy 6 stocks in Day 1 and sell them in Day 2, after which we will have 1216 yen.



Sample input:
7
100 130 130 130 115 115 150


Sample output:
1685

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    a.append(0)
    pre = 10**9
    kabu = 0
    ans = 1000
    flag1,flag2 = False,False
    if a[0]<a[1]:
        flag2 = True
    else:
        flag1 = True
    for i in range(n+1):
        if flag1==True and a[i]> pre:
            kabu += ans//pre
            ans -= kabu*pre
            flag1,flag2 = False,True
        elif flag2==True and a[i]<pre:
            ans += kabu*pre
            kabu = 0
            flag1,flag2 = True,False
        pre = a[i]
        #print(ans,kabu)
    print(ans)

main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
money = 1000
kabu = 0
if a[0] < a[1]:
    flg = 'kau'
elif a[0] > a[1]:
    flg = 'uru'
else:
    flg = 'f'
for i in range(1,n):
    if a[i-1] < a[i]:
        if flg != 'uru':
            kabu = money // a[i-1]
            money -= kabu * a[i-1]
            flg = 'uru'
    elif a[i-1] > a[i]:
        if flg != 'kau':
            money += kabu * a[i-1]
            kabu = 0
            flg = 'kau'
    else:
        pass
if kabu > 0:
    money += kabu * a[-1]
print(money)

Submission status: Accepted

Solution code:
n = int(input())
s = list(map(int, input().split()))

m = 1000
stock = 0

for i in range(n-1):
  if s[i+1] >= s[i]:
    #buy
    stock = stock + m // s[i]
    m = m - s[i]*(m//s[i])
  else:
    #sell
    m = m + stock*s[i]
    stock = 0

an  = m + stock*s[n-1]
print(an)

Submission status: Accepted

Solution code:
N = int(input())
A = list(int(a) for a in input().split())
A.extend([0])

money = 1000
stock = 0

for i in range(N):
    if A[i] < A[i+1] and money >= A[i]:
        stock += money // A[i]
        money %= A[i]
    if A[i] > A[i+1]:
        money += stock * A[i]
        stock = 0

print(money)

Submission status: Accepted

Solution code:
n = int(input())
*A, = map(int, input().split())
ans = 1000
for i in range(n - 1):
    ans += (ans // A[i]) * max(A[i + 1] - A[i], 0)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
#n,k=map(int,input().split())
al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
stock = 0
money = 1000
for i in range(n-1):
    sell = stock*al[i]
    stock = 0
    money += sell
    if al[i] < al[i+1]:# buy
        buynum = money//al[i]
        stock= buynum
        money -= buynum*al[i]

print(money + stock*al[n-1])

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
t = 1000
for i in range(n-1):
    if a[i] < a[i+1]:
        t += (t//a[i])*(a[i+1]-a[i])
print(t)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    current = 1000
    prev = A[0]
    for a in A[1:]:
        if prev < a:
            n = current // prev
            current = a * n + (current % prev)
        prev = a
    print(current)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


def main():
    import sys
    input = sys.stdin.readline

    n = int(input())
    a = list(map(int, input().split()))
    money = 1000

    # 反省点:
    # 難しく考えすぎて、実装しきれなかった。
    # ある時点で最も安い値のときに買って、最も高いときに売る、という考え方をしていた。
    # 「何もしない」「買う」「売る」の3パターンを愚直に遷移させようとしていた。

    # KeyInsight:
    # 「i日目には、その時点で所持する金と株の範囲内で、M君は次の取引を何回でも行えます。」を、
    # = i日目の最初に全て売る + 必要に応じて買い戻す と言い換える。
    # See:
    # https://www.youtube.com/watch?v=z6SeLXdwVhA&feature=youtu.be

    for i in range(n - 1):
        today = a[i]
        tomorrow = a[i + 1]

        if tomorrow > today:
            count = money // today
            money %= today
            money += tomorrow * count

    print(money)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding:utf-8
n = int(input())
a = list(map(int, input().split()))
money = 1000

for i in range(n - 1):
    stock = 0
    if a[i] < a[i + 1]:
        stock = money // a[i]
    money += (a[i + 1] - a[i]) * stock

print(money)

Submission status: Accepted

Solution code:
n = int(input())
A = [*map(int, input().split())]
yen = 1000
for i in range(n-1): yen += max(0, yen//A[i] * (A[i+1] - A[i]))
print(yen)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
money = 1000

for i in range(n-1):
    if a[i] < a[i+1]:
        money = money//a[i] * a[i+1] + money%a[i]

print(money)

Submission status: Accepted

Solution code:
N=int(input())
A = list(map(int, input().split()))
money=1000
stock=0
if A[0]<A[1]:
    stock=int(money/A[0])
    money=money-A[0]*stock
for i in range(1,N-1):
    if A[i-1]<A[i]:
        money=money+A[i]*stock
        stock=0
    if A[i]<A[i+1]:
        stock=int(money/A[i])
        money=money-A[i]*stock
money=money+A[N-1]*stock        
print(money)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
kane = 1000
kabu = 0 
if a[0] < a[1]:
    kabu = kane // a[0]
    kane %= a[0]
for i in range(1, n - 1):
    if a[i - 1] < a[i]:
        kane += a[i] * kabu
        kabu = 0
    if a[i] < a[i + 1]:
        kabu = kane // a[i]
        kane %= a[i]
kane += a[n - 1] * kabu
print(kane)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 1000
for i in range(n-1):
    if a[i] < a[i+1]:
        ans += (a[i+1]-a[i])*(ans//a[i])
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
A = [*map(int, input().split())] + [0]
dp_yen = [1000]*(n+1)
for day in range(n):
    dp_yen[day+1] = max(dp_yen[day], dp_yen[day] + dp_yen[day]//A[day] * (A[day+1] - A[day]))
print(dp_yen[n])

Submission status: Accepted

Solution code:
n = int(input())
A = [*map(int, input().split())] + [0]
dp_yen = [0]*(n+1)
dp_yen[0] = 1000
for day in range(n):
    dp_yen[day+1] = max(dp_yen[day], dp_yen[day] + (A[day+1] - A[day]) * (dp_yen[day] // A[day]))
print(dp_yen[n])

Submission status: Accepted

Solution code:
n = int(input())
A = [0] + [*map(int, input().split())] + [0]
dp_yen = [0]*(n+1)
dp_yen[1] = 1000
for day in range(1, n):
    stock = 0
    if A[day] > 0: stock = dp_yen[day] // A[day]
    remain = dp_yen[day] - stock*A[day]
    dp_yen[day+1] = max(dp_yen[day], remain + stock * A[day+1])
print(dp_yen[n])

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]


def main():
    N = int(input())
    A = list(map(int,input().split()))
    zougen = [-1 if A[i] > A[i + 1] else 1 for i in range(N - 1)]
    money = 1000
    kabu = 0
    for i in range(N-1):
        if zougen[i] == 1:
            kabu += money // A[i]
            money = money % A[i]
        else:
            money += kabu * A[i]
            kabu = 0
    print(A[-1] * kabu + money)



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
A = [0] + [*map(int, input().split())]
dp_stock = [0]*(n+1)
dp_yen = [0]*(n+1)
dp_yen[0] = 1000
for day in range(1, n+1):
    dp_stock[day] = max(dp_stock[day-1], dp_yen[day-1] // A[day])
    remain = dp_yen[day-1] - dp_stock[day-1]*A[day-1]
    dp_yen[day] = max(dp_yen[day-1], remain + dp_stock[day-1] * A[day])
print(dp_yen[n])

Submission status: Accepted

Solution code:
n = int(input())

a = [0 for _ in range(n)]
a = [int(s) for s in input().split()]


st_num = 0
mny = 1000

for i in range(n-1):
    now_mn = a[i]
    next_mn = a[i+1]
    
    #print(st_num,mny)
    if(next_mn > now_mn):
        st_num += mny//now_mn
        mny = mny%now_mn
    else:
        mny += st_num*now_mn
        st_num = 0

if(a[n-1] > a[n-2] and st_num > 0):
    mny += st_num*a[n-1]
    st_num = 0

print(mny)

Submission status: Accepted

Solution code:
n = int(input())
arr = list(map(int,input().split()))
cache = 1000
numStock = 0
for i in range(1,n):
    if arr[i]>arr[i-1]:
        available = cache//arr[i-1]
        cache -= arr[i-1]*available
        numStock += available
    else:
        cache += arr[i-1]*numStock
        numStock = 0

if numStock>0:
    cache += arr[-1]*numStock

print(cache)

Submission status: Accepted

Solution code:
def sell(rate,kabu):
    money = rate * kabu
    return money
    
def buy(rate,money):
    kabu = money//rate
    otsuri = money % rate
    return kabu,otsuri
    
N,*A = map(int,open(0).read().split())
max_money = 1000
have_money = 1000
have_kabu = 0
for i in range(N-1):
    if A[i] < A[i+1] and have_money > A[i]: #買う
        have_kabu,have_money = buy(A[i],have_money)
    if A[i] > A[i+1]: #売る
        have_money += sell(A[i],have_kabu)
        have_kabu = 0
        max_money = max(max_money,have_money)
have_money += sell(A[-1],have_kabu)    
max_money = max(max_money,have_money)
print(max_money)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))

i = 0

yen = 1000
while i < N:
    while i < N - 1 and A[i] >= A[i + 1]:
        i += 1

    if i == N - 1:
        break

    x = i
    while i < N - 1 and A[i] <= A[i + 1]:
        i += 1

    y = i

    cnt = yen // A[x]
    yen = yen - A[x] * cnt + A[y] * cnt

print(yen)

Submission status: Accepted

Solution code:
def sell(rate, kabu):
    return rate * kabu
    
def buy(rate, money):
    kabu = money//rate
    otsuri = money % rate
    return kabu, otsuri
    
N,*A = map(int, open(0).read().split())
money = 1000
have_kabu = 0
for i in range(N):
    #売る
    money += sell(A[i], have_kabu)
    have_kabu = 0
    #買う    
    if i != N-1 and A[i] < A[i+1]: 
        have_kabu, money = buy(A[i], money)
print(money)

Submission status: Accepted

Solution code:
# D - Road to Millionaire
def sell(price):
  global money
  global stock
  
  money += price * stock
  stock = 0


def buy(price):
  global money
  global stock

  stock += money // price
  money %= price


N = int(input())
A = list(map(int, input().split()))

money = 1000
stock = 0

for i in range(N - 1):
  if A[i] < A[i + 1]:
    sell(A[i])
    buy(A[i])
  elif A[i + 1] < A[i]:
    sell(A[i])

sell(A[N - 1])

print(money)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))

kab=0
mon=1000

for i in range(n-1):
    if a[i]<a[i+1]:
        x=mon//a[i]
        kab+=x
        mon-=x*a[i]
    else:
        mon+=kab*a[i]
        kab=0

mon+=a[-1]*kab

print(mon)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.append(0)

money = 1000
kabu = 0

for i in range(N):
    if kabu > 0:
        money += kabu*A[i]
        kabu = 0
    if A[i] < A[i+1]:
        kabu = money//A[i]
        money -= (money//A[i])*A[i]

print(money)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = a + [0]
state = a[0]
money = 1000
stock = 0
for i in range(1, n+1):
  if state < a[i] and stock == 0:
    stock += (money // state)
    money %= state
  elif state > a[i] and stock > 0:
    money += (stock * state)
    stock = 0
  state = a[i]
print(money)

Submission status: Accepted

Solution code:
N = int(input())
An = list(map(int, input().split()))
dp = [0 for x in range(N+10)]
An.insert(0, 0)
dp[1] = 1000
for i in range(2, N+1):
    stock = dp[i-1] // An[i-1]
#     print(dp[i-1], An[i-1], stock)
    money = dp[i-1]
    money -= stock * An[i-1]
    money += stock * An[i]
#     print(money)
    dp[i] = max(dp[i-1], money)
print(dp[N])

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]

m = 1000
s = 0
for i in range(N-1):
    if A[i] > A[i+1]:
        m += s*A[i]
        s = 0
    else:
        s += m//A[i]
        m %= A[i]

print(m+s*A[-1])

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))

money = 1000
for x, y in zip(a[:-1], a[1:]):
    if x < y:
        stocks = money // x
    else:
        stocks = 0
    money += (y - x) * stocks

print(money)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
z1=1000
for i in range(n-1):
    if a[i]<a[i+1]:
        z1=z1//a[i]*a[i+1]+z1%a[i]
print(z1)

Submission status: Accepted

Solution code:
def function(N, A):
    money = 1000
    kabu = 0
    for i in range(N-1):
        if A[i] < A[i+1]:
            kabu = int(money/A[i])
            money += (A[i+1]-A[i])*kabu
    print(money)


if __name__ == '__main__':
    N = int(input())
    A = input().split()
    A = [int(a) for a in A]
    function(N, A)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))

m = 1000
k = 0
for i in range(N-1):
    if A[i] > A[i+1]:
        m += k * A[i]
        k = 0
    elif A[i] < A[i+1]:
        m += k * A[i]
        k = m // A[i]
        m -= k * A[i]
    else:
        pass
m += (k * A[-1])
print(m)

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))

g=1000

for s1,s2 in zip(A[:-1],A[1:]):
    if s1<s2:
        stockNum=g//s1
        g+=stockNum*(s2-s1)

print(g)

Submission status: Accepted

Solution code:
n = int(input())
a=list(map(int,input().split()))
 
kane=1000
kabu =0
 
for i in range(n-1):
    if a[i]<=a[i+1]:
        kabu+=kane//a[i]
        kane=kane%a[i]
    else:
        kane+=kabu*a[i]
        kabu=0

print(kane+kabu*a[n-1])

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))

ans = 0

lst = [1000] * (N)

for i in range(N): #買うところを選択
    a = A[i]
    for j in range(i + 1, N):
        if A[j] > a:
            tmp = lst[i] // a * A[j] + lst[i] % a
            lst[j] = max(max(lst[j], tmp), lst[j - 1])
        else:
            lst[j] = max(lst[j], lst[j - 1])

print (lst[-1])
# print (lst)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.append(0)

buy = A[0]
ans = 1000
for i in range(1, N):
  if A[i] > A[i+1] and buy < A[i]:
    ans = ans % buy + ans // buy * A[i]
    buy = 500
  elif buy > A[i]:
    buy = A[i]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
# for i in range(N):
#     A[i] = int(i)
cMoney = 1000
stock = 0
A.append(0)
for i in range(N):
    stock = 0

    if A[i] < A[i+1]:
        stock = cMoney // A[i]
        cMoney -= stock * A[i]
    cMoney += A[i+1] * stock



    

print(cMoney)

# for i in range(N):
#     stock = 0
#     if A[i] < A[i+1]:
#         stock = cMoney // A[i]

#     cMoney += (A[i+1] - A[i]) * stock
# print(cMoney)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split())) + [0]
kabu = 0
money = 1000

for p in range(N):
    #株がない時
    if A[p] < A[p+1]:
        kabu += money//A[p]
        money -= (money//A[p])*A[p]
    
    #株があるとき
    if A[p] > A[p+1]:
        money += kabu*A[p]
        kabu = 0 
    #print(str(p+1) + "日目" + str(money) + "  " +str(kabu))

print(money)

Submission status: Accepted

Solution code:
N = int(input())
A = [0] * (N + 1)
A = list(map(int,input().split()))
# for i in range(N):
#     A[i] = int(i)
cMoney = 1000
stock = 0
A.append(0)
# for i in range(N):
#     if i == N - 1:
#         if stock > 0:
#             cMoney += A[i] * stock
#             stock = 0
#         continue

#     if A[i] >= A[i+1]:
#         if stock > 0:
#             cMoney += A[i] * stock
#             stock = 0
#     else:
#         stock = cMoney // A[i]
#         cMoney -= stock * A[i]

# print(cMoney)

for i in range(N):
    stock = 0
    if A[i] < A[i+1]:
        stock = cMoney // A[i]

    cMoney += (A[i+1] - A[i]) * stock
print(cMoney)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))

amount = 1000
MX = A[0]
MN = A[0]

for i in range(1, N):
	a = A[i]
	if a < MX:
		if MN < MX:
			s = amount // MN
			t = amount % MN
			amount = MX * s + t
		MN = a
		MX = a
	else:
		if a > MX:
			MX = a
		if a < MN:
			MN = a

	if i == N - 1 and MN < MX:
		s = amount // MN
		t = amount % MN
		amount = MX * s + t

print(amount)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
total = 1000
for i in range(1, N):
    if A[i] > A[i-1]:
        total += (total // A[i-1]) * (A[i]-A[i-1])
print(total)

Submission status: Accepted

Solution code:
n=int(input())
I=list(map(int,input().split()))
num=1000
for i in range(n-1):
    if I[i]<I[i+1]:
        p=num//I[i]
        num-=p*I[i]
        num+=p*I[i+1]

print(num)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
money = 1000

for i in range(1, n):
    if a[i] > a[i - 1]:
        cnt = money // a[i - 1]
        money = cnt * a[i] + money % a[i - 1]
print(money)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
cnt=0
ans=1000
for i in range(1,n):
    if a[i-1]<a[i]:
        cnt+=ans//a[i-1]
        ans-=cnt*a[i-1]
        ans+=cnt*a[i]
        cnt=0
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

N = int(input())
A = list(map(int, input().split()))

money = 1000
stock = 0

for i in range(N-1):
    
    if A[i] < A[i+1]:
        stock = money // A[i]
        money += stock * (A[i+1] - A[i])
        # print(money, stock) 
        
print(money)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))

#最初の所持金
money = 1000
#株の所持数
kabu_c = 0

l = []
#予言で翌日上がるかどうかのリスト
for i in range(n-1):
    if A[i+1] - A[i] > 0:
         l.append(1)
    else:
         l.append(0)

#株の購入
#enumerateを使うと便利、変に勘違いすることもなさそう。
for idx, i in enumerate(l):
    if i == 1 and money - A[idx] >= 0:
        kabu_c = money // A[idx]
        money = money - kabu_c * A[idx]
    if i == 0:
        money = money + kabu_c * A[idx]
        kabu_c = 0

if kabu_c > 0:
    money = money + kabu_c * A[n-1]
print(money)

Submission status: Accepted

Solution code:
n=int(input())
ar=list(map(int,input().split()))
li=[]
bo=True
for i in range(n-1):
	if bo and ar[i+1]>=ar[i]:
		li.append(ar[i])
		bo=False
	elif not bo and ar[i]>ar[i+1]:
		li.append(ar[i])
		bo=True
if len(li)==0:
	print(1000)
	exit()
if bo and li[-1]==ar[n-2]:
	if ar[n-1]>ar[n-2]:
		li.pop()
		li.append(ar[n-1])
if not bo:
	li.append(ar[-1])
s=1000
l=len(li)
for i in range(0,l,2):
		a=li[i]
		b=li[i+1]
		x=s//a
		r=s%a
		s=b*x+r
print(s)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
ans = 1000
for i in range(n - 1):
    if A[i] < A[i + 1]:
        ans += ans // A[i] * (A[i + 1] - A[i])
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
m=1000
for i in range(n-1):
    if a[i]<a[i+1]:
        m+=m//a[i]*(a[i+1]-a[i])
print(m)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()]

money=1000
kabukosuu=0

for i in range(n-1):
    money+=kabukosuu*a[i]
    kabukosuu=0
    if a[i]<a[i+1]:
        kabukosuu=money//a[i]
        money=money%a[i]
    
money+=kabukosuu*a[n-1]

print(money)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.append(0)

x = 1000
y = 0

for i in range(n):
    if a[i] < a[i+1]:
        y += x // a[i]
        x %= a[i]
    elif a[i] > a[i+1]:
        x += y * a[i]
        y = 0

print(x)

Submission status: Accepted

Solution code:
n = int(input())

a = list(map(int,input().split()))

memo = [0]*n

memo[0] = 1000

for i in range(1,n):
    memo[i] = max((memo[i-1]%a[i-1]+a[i]*(memo[i-1]//a[i-1])),memo[i-1])

print(memo[-1])

Submission status: Accepted

Solution code:
n = int(input())

a = list(map(int,input().split()))

money = 1000

for i in range(1,n):
    if a[i-1] < a[i]:
        money = money%a[i-1]+a[i]*(money//a[i-1])

print(money)

Submission status: Accepted

Solution code:
M = int(input())
A = [int(_) for _ in input().split()]
N = 1000
kabu = 0
if A[0] < A[1]:
    kabu, N = divmod(N, A[0])
for a, b, c in zip(A, A[1:], A[2:]):
    if a <= b >= c:
        N += kabu * b
        kabu = 0
    elif a >= b <= c:
        dkabu, N = divmod(N, b)
        kabu += dkabu
N += kabu * A[-1]
print(N)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
v = 1000
s = 0
for i in range(n - 1):
    if a[i] < a[i + 1]:
        s = v // a[i]
        v += (a[i + 1] - a[i]) * s
print(v)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    m = 1000
    sell = False
    buyp = A[0]
    sellp = None
    for i in range(1, N):
        if (not sell) and (buyp > A[i]):
            buyp = A[i]
        elif (not sell):
            sell = True
            sellp = A[i]
        if sell and (sellp < A[i]):
            sellp = A[i]
        elif sell:
            s = m // buyp
            m = s * sellp + (m % buyp)
            buyp = A[i]
            sell = False
    return m
print(main())

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))

from collections import deque


cash = 1000
stock = 0

peak_min = deque()
peak_max = deque()

d_prev = 0
for i in range(1, n):
    a = A[i]
    if A[i] > A[i-1]:
        d = 1
    elif A[i] == A[i-1]:
        d = d_prev
    else:
        d = -1
    if d_prev*d == -1:
        if d == 1:
            peak_min.append(i-1)
        elif d == -1:
            peak_max.append(i-1)
    d_prev = d
#print(peak_min, peak_max)

if len(peak_min) == 0 and len(peak_max) == 0:
    if A[0] < A[-1]:
        ans = cash%A[0] + cash//A[0]*A[-1]
    else:
        ans = cash
elif len(peak_min) == 0:
    ans = cash%A[0] + cash//A[0]*A[peak_max[0]]
elif len(peak_max) == 0:
    ans = cash%A[peak_min[0]] + cash//A[peak_min[0]]*A[-1]
else:
    if peak_max[0] < peak_min[0]:
        peak_min.appendleft(0)
    if peak_max[-1] < peak_min[-1]:
        peak_max.append(n-1)
#    print(peak_min, peak_max)
    
    while len(peak_min) != 0:
        i = peak_min.popleft()
        stock += cash//A[i]
        cash = cash%A[i]
#        print(i, cash , stock)
        
        i = peak_max.popleft()
        cash += stock*A[i]
        stock = 0
#        print(i, cash , stock)
    ans = cash
print(ans)

Submission status: Accepted

Solution code:
M = int(input())
A = [int(_) for _ in input().split()]
N = 1000
if all(a >= b for a, b in zip(A, A[1:])):
    print(N)
else:
    kabu = 0
    if A[0] < A[1]:
        kabu, N = divmod(N, A[0])
    for a, b, c in zip(A, A[1:], A[2:]):
        if a <= b >= c:
            N += kabu * b
            kabu = 0
        elif a >= b <= c:
            dkabu, N = divmod(N, b)
            kabu += dkabu
    N += kabu * A[-1]
    print(N)

Submission status: Accepted

Solution code:
N = int(input())
arr = list(map(int, input().split()))
dp = [1000]*N
for i in range(1,N):
    dp[i] = max((dp[i-1]//arr[i-1])*arr[i]+dp[i-1]%arr[i-1],dp[i-1])
print(dp[-1])

Submission status: Accepted

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
a = nl()

dp=[0]*(n+1)
dp[0] = 1000

for i in range(1,n):
  dp[i]=dp[i-1]
  for j in range(i):
    v = dp[j] // a[j]
    w = dp[j] + (a[i]-a[j])*v
    dp[i] = max(dp[i],w)
print(dp[n-1])

Submission status: Accepted

Solution code:
# DP法でトライ
N = int(input())
A = list(map(int, input().split()))

# i 日目に、株の売却が終了した時点の所持金の最大値
dp = [0]*N
dp[0] = 1000

for i in range(1,N):
    for j in range(0,i):
        dp[i] = max(dp[i], dp[i-1],(dp[j]//A[j])*A[i]+dp[j]%A[j])

print(dp[-1])

Submission status: Accepted

Solution code:




n=int(input())
a=list(map(int,input().split()))


res=1000

for i in range(1,n):

    if a[i]>a[i-1]:
        t=(res//a[i-1])*a[i]+res%a[i-1]
        res=t


print(res)

Submission status: Accepted

Solution code:
N= int(input())
A = list(map(int,input().split()))
A.insert(0,A[0])
A.append(0)
 
money = 1000
previous_tendency = "remain"
current_tendency = "remain"
count = 1

#print(A)
 
for n in range(1,len(A)-1):
    if A[n] < A[n+1]:
        current_tendency = "up"
    elif A[n] > A[n+1]:
        current_tendency = "down"
    else:
        current_tendency = "remain"
        
    if previous_tendency != "down" and current_tendency != "up":
        #print(money,n,"chance",A[n],min(A[count:n+1]),previous_tendency, current_tendency)
        money += (money//min(A[count:n+1]))*(A[n]-min(A[count:n+1]))
        #print(A[count:n+1],money)
        count = n + 1
        previous_tendency = "remain"
    #print(A[n],max_price,min_price,previous_tendency,current_tendency)
    
    if current_tendency != "remain":
      previous_tendency = current_tendency
print(money)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))

l=[]
for x in range(n-1):
    if a[x+1]==a[x]:l.append(0)
    if a[x+1]>a[x]:l.append(1)
    if a[x+1]<a[x]:l.append(-1)

for x in range(n-1):
    if l.pop(-1)==1:
        l.append(1)
        l.append(-1)
        break

m=1000
p=0
for i,x in enumerate(l):
    if x==1:
        t=m//a[i]
        m-=t*a[i]
        p+=t
    if x==-1:
        m+=p*a[i]
        p=0
print(m)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
m=1000
s=0
for i in range(n-1):
  if a[i]<a[i+1]:
    s+=m//a[i]
    m=m%a[i]
  else:
    m+=s*a[i]
    s=0
print(m+a[n-1]*s)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))

amount = 1000

for i in range(N - 1):
    if A[i] < A[i + 1]:
        stock = amount // A[i]
        amount += (A[i + 1] - A[i]) * stock

print(amount)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
x = []
flag = True
for i in reversed(range(n)):
    if i == 0:
        if not flag:
            x.append(a[i])
        break
    flag2 = flag
    if flag:
        if a[i - 1] < a[i]:
            x.append(a[i])
            flag2 = not flag2
    else:
        if a[i - 1] > a[i]:
            x.append(a[i])
            flag2 = not flag2
    flag = flag2
x = x[::-1]
m = len(x)
if m % 2 == 1:
    x = x[1:]
# print("x =", x)
cur_money = 1000
cur_stock = 0
for i in range(m):
    if i % 2 == 0:
        cur_stock += cur_money // x[i]
        cur_money %= x[i]
    else:
        cur_money += x[i] * cur_stock
        cur_stock = 0
print(cur_money)

Submission status: Accepted

Solution code:
# D - Road to Millionaire


def million(n, a):
    wallet = 1000
    i = 0
    while i < n - 1:
        highest_price = a[i]
        cheapest_price = a[i]
        # 直近の最高値と最安値を取得する
        for j in range(i + 1, n):
            if highest_price > a[j]:
                break
            if highest_price < a[j]:
                highest_price = a[j]
            if cheapest_price > a[j]:
                cheapest_price = a[j]
        if highest_price > cheapest_price:
            # 取引する
            stock = wallet // cheapest_price
            wallet = wallet - stock * cheapest_price
            wallet = wallet + stock * highest_price
            i = j
        else:
            i += 1
    return wallet


if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))
    print(million(n, a))

Submission status: Accepted

Solution code:
N = int(input())
stocks = list(map(int, input().split()))
curr = 1000
for i in range(N - 1):
  cnt = 0
  if stocks[i] < stocks[i + 1]:
    cnt = curr // stocks[i]
  curr += cnt * (stocks[i + 1] - stocks[i])
print(curr)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = 1000
for i in range(N-1):
    if A[i] < A[i+1]:
        temp = ans // A[i]
        ans -= temp*A[i]
        ans += temp*A[i+1]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
arr = list(map(int,input().split()))
cur=1000
for i in range(n-1):
  p=0
  if arr[i] < arr[i+1]:
    p=cur // arr[i]
  cur += (arr[i+1] - arr[i])*p
print(cur)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))

# DP
# dp[i]: i日目の所持金の最大値（持ち株は売る）
dp = [0] * n
dp[0] = 1000

# dp[1] = 0日目に全部買って1日目に全部売る or 0日目から何もしない
# dp[2] = 0 or 1日目に全部買って2日目に全部売る or 1日目から何もしない
# dp[i+1] + 0~i日目のどこかで全部買ってi+1日目に全部売る or i日目から何もしない
for i in range(n):
    if i == 0:
        dp[i] = 1000
        continue
    
    dp[i] = dp[i-1]
    for j in range(i):
        # j日目に全部買ってi日目に全部売る
        dp[i] = max(dp[i], (dp[j] // a[j]) * a[i] + dp[j] % a[j])
    
print(dp[n-1])

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))

money = 1000
for i in range(n-1):
    stocks = 0
    if a[i] < a[i + 1]:
        stocks = money // a[i]
    money += (a[i+1] - a[i]) * stocks
print(money)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))

dp=[0]*(N)
dp[0]=1000
for i in range(1,N):
    for j in range(i+1):
        stock=dp[i-j]//A[i-j]
        money=stock*A[i]+dp[i-j]-stock*A[i-j]
        dp[i]=max(dp[i],dp[i-j],money)
print(dp[N-1])

Submission status: Accepted

Solution code:
n = int(input())
a_list = list(map(int, input().split()))

money = 1000
num = 0

for i in range(len(a_list)-1):
    if a_list[i] <= a_list[i+1]:
        num += money // a_list[i]
        money -= num * a_list[i]

        money += num * a_list[i+1]
        num = 0

print(money)

Submission status: Accepted

Solution code:
n, *a = map(int, open(0).read().split())
money = 1000
stock = 0
for i in range(n-1):
    if a[i] < a[i+1]:
        stock = money // a[i]
        money += (a[i+1] - a[i]) * stock
print(money)

Submission status: Accepted

Solution code:
n, *a = map(int, open(0).read().split())
max_a = max(a)
money = 1000
stock = 0
for i in range(n-1):
    if a[i] < a[i+1]:
        stock = money // a[i]
        money += (a[i+1] - a[i]) * stock
print(money)