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:

# D Road to Millionaire
N = int(input())
A = list(map(int, input().split()))
i = 0
M =1000
while i in range(N - 1):
    if A[i] >= A[i+1]:
        i = i + 1   
    else:
        m = (A[i+1] - A[i]) * (M // A[i])
        M = M + int(m)
        i = i + 1
print(M)

Submission status: Accepted

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

Submission status: Accepted

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

def sell(money,stock,price):
  money += price*stock
  stock = 0
  return money, stock

def buy(money,price):
  stock,money = divmod(money,price)
  return money,stock

money = 1000
stock = 0
for i in range(N):
  money, stock = sell(money,stock,A[i])
  if i<N-1 and A[i]<A[i+1]:
    money, stock = buy(money,A[i])
print(money)

Submission status: Accepted

Solution code:
import sys
imput = sys.stdin.readline

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

money = 1000

for i in range(N-1):
  if a[i+1] > a[i]:
    k = money//a[i]
    money += a[i+1]*k - a[i]*k
    
print(money)

Submission status: Accepted

Solution code:
import sys

N = int(input())
A = list(map(int, sys.stdin.readline().rsplit()))

dp = [0] * N
dp[0] = 1000

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

print(dp[N - 1])

Submission status: Accepted

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

money = 1000
stock = 0

for i in range(1, n):
    if A[i-1] > A[i]:
        money += stock * A[i-1]
        stock = 0
    else:
        stock += money // A[i-1]
        money %= A[i-1]
else:
    money += stock * A[-1]
    stock = 0

print(money)

Submission status: Accepted

Solution code:
a=[input() for i in range(2)]
a1=int(a[0])
a2=[int(i) for i in a[1].split()]

money=1000
kabu=0

for i in range(a1-1):
	if a2[i]<a2[i+1]:
		kabu=int(money/a2[i])
		money+=kabu*(a2[i+1]-a2[i])

print(money)

Submission status: Accepted

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

'''
ans = 1000
for i in range(n - 1):
    x = a[i]
    y = a[i + 1]
    if x < y:
        k = ans // x
        ans %= x
        ans += k * y

print(ans)
'''

dp = [0] * (n + 10)
dp[1] = 1000
for i in range(2, n + 1):
    dp[i] = dp[i - 1]
    for j in range(1, i):
        x = dp[j] // a[j]
        y = dp[j] + (a[i] - a[j]) * x
        dp[i] = max(dp[i], y)

ans = dp[n]
print(ans)

Submission status: Accepted

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

money = 1000
stock = 0

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    A = list(map(int, input().split()))
    tmp = 1000
    for i in range(N-1):
        if A[i] < A[i+1]:
            s = tmp//A[i]
            tmp %= A[i]
            tmp += s * A[i+1]
    print(tmp)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

    money = 1000
    stock = 0
    for i in range(N - 1):
        stocks = money // A[i] if A[i] < A[i + 1] else 0
        money += (A[i + 1] - A[i]) * stocks
    return money

print(d_road_to_millionaire())

Submission status: Accepted

Solution code:
N = int(input(""))
a = input("").split(" ")
a = [int(i) for i in a]
m = 1000
list_ = []

for j in range(0, N-1):
    if a[j] < a[j + 1]:
        n = m // a[j]
        k = (a[j + 1] - a[j]) * n
        m = m + k

print(m)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 1000

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 7
# 100 130 130 130 115 115 150
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))
m = 1000
kabu = 0
buy = True
buy_val = 100000

for i in range(len(a)):
    if i == len(a)-1:
        m += kabu * a[i]
        kabu = 0

    elif not buy and a[i] > a[i+1]:
        m += kabu * a[i]
        kabu=0
        buy=True
    elif buy and a[i] < a[i+1]:
        kabu=int(m/a[i])
        m -= kabu * a[i]
        buy=False

print(m)

Submission status: Accepted

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

'''
ans = 1000
for i in range(n - 1):
    x = a[i]
    y = a[i + 1]
    if x < y:
        k = ans // x
        ans %= x
        ans += k * y

print(ans)
'''

dp = [0] * (n + 10)
dp[1] = 1000
for i in range(2, n + 1):
    dp[i] = dp[i - 1]
    for j in range(1, i):
        x = dp[j] // a[j]
        y = dp[j] + (a[i] - a[j]) * x
        dp[i] = max(dp[i], y)

ans = dp[n]
print(ans)

Submission status: Accepted

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

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

print(current_money)

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 = [int(x) for x in input().split()]
# 最初の所持金
money = 1000
# 所有株数
kabu_c = 0
# 予言で翌日上がるかどうかのリスト
l = list()
for i in range(n-1):
    if A[i+1] - A[i] > 0:
        l.append(1)
    else:
        l.append(0)
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())
A = list(map(int, input().split()))
assets = 1000               # 資産

# 売買するかどうかのフラグ(買→1、売→0)をリストで生成
# (所持資産・所持株数を最大限に使い切って行う)
flag = []
for n in range(N-1):
    if A[n] <= A[n+1]:      # 当日の株価 <= 翌日の株価 ⇒ 買う
        flag.append(1)
    else:
        flag.append(0)      # 当日の株価 > 翌日の株価 ⇒ 売る
flag.append(0)              # 最終日は売る
# print(flag)

amount = 0                  # 所持株数
for idx, f in enumerate(flag):      # 売買処理
    if f == 1:
        purchase = assets // A[idx] # 購入数
        amount += purchase
        assets -= purchase * A[idx]
    else:
        assets += amount * A[idx]
        amount = 0
    # print(assets, amount)

print(assets)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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]
    money+=stock*A[i+1]
print(money)

Submission status: Accepted

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

prev = a[0]
mon = 1000
stc = 0

for i in range(1, n):
    #print(prev)
    if prev < a[i]:
        stc = mon // prev
        mon = mon - stc * prev
        mon = stc * a[i] + mon
        #print("stc = {} mon = {}" .format(stc, mon))
    elif prev >= a [i]:
        pass
        #print("stc = {} mon = {}" .format(stc, mon))
    prev = a[i]

#mon = mon + stc * a[n - 1]

print(mon)

Submission status: Accepted

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

current = 1000
kabu = 0

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

print(current)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
money = 1000
kabu = 0
for i in range(n-1):
    if a[i] < a[i+1]:
        kabu = money//a[i] * a[i+1] #持ち株数×時価
        money = (money % a[i]) + kabu
print(money)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    a = LI()

    r = 1000
    t = []
    sf = True
    for i in range(n-1):
        if sf:
            if a[i] >= a[i+1]:
                continue
            t.append(a[i])
            sf = False
        else:
            if a[i] <= a[i+1]:
                continue
            t.append(a[i])
            sf = True

    if len(t) == 0:
        return r

    if t[-1] != a[-1]:
        t.append(a[-1])

    for i in range(len(t)//2):
        b = t[i*2]
        c = t[i*2 + 1]
        k = r // b
        r += (c-b) * k

    return r

print(main())

Submission status: Accepted

Solution code:
n, *a = map(int, open(0).read().split())
a += 1,
m = 1000

def groupby():
  c, res = [], []
  for i in range(n + 1):
    if a[i-1] <= a[i]:
      pass
    else:
      res += [c[0], c[-1]],
      c = []
    c += a[i],
  return res

for i, j in groupby():
  m = m // i * j + m % i
print(m)

Submission status: Accepted

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

Submission status: Accepted

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

budget = 1000
stock = 0
for i in range(n-1):
    if l[i] < l[i+1]:
        budget = budget + stock * l[i]
        stock = budget // l[i]
        budget = budget % l[i]
    elif l[i] > l[i+1]:
        budget = budget + stock * l[i]
        stock = 0
else:
    budget += stock*l[-1]
    stock = 0

print(budget)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
ans = 1000
for i in range(n-1):
    x = ans // a[i]
    if a[i] < a[i+1]:
        ans -= x * a[i]
        ans += x * a[i+1]
print(ans)

Submission status: Accepted

Solution code:
_input = input
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

#ここに書きたいコードを書く
#データ読み込み
#n=int(input())
m=input().split()
n=int(m[0])
#s=[list(map(int, input().split())) for i in range(n)]
s=list(map(int, input().split()))

day_money = [0] * n
day_money[0] = 1000

for sell_day in range(n):
	for buy_day in range(sell_day):
		day_money[sell_day] = max(day_money[buy_day], (day_money[buy_day]//s[buy_day])*s[sell_day]+day_money[buy_day]%s[buy_day])
		#print(day_money)
		
print(day_money[n-1])

input = _input

Submission status: Accepted

Solution code:
n=int(input())
a=[float('inf')]
a+=list(map(int,input().split()))
d=[1000 for i in range(n+1)]
for i in range(1,n+1):
    d[i]=max(d[i-1],d[i-1]//a[i-1]*a[i]+d[i-1]%a[i-1])
print(d[-1])

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    N = int(input())
    As = [int(item) for item in input().split()]

    deff_list = [0]
    for i in range(1,N):
        deff_list.append(As[i] - As[i-1])

    prev = 1000
    res = 1000
    for i in range(1, N):
        if deff_list[i] >= 0:
            res = (prev // As[i-1]) * As[i] + prev % As[i-1]
        
        prev = res
    
    print(res)



if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
mon = 1000  #所持金
cnt = 0  #株の所持数
cur = A[0]
for i in range(1,len(A)):
  sec = A[i]
  #値上がりする前に購入
  if cur < sec:
    #買えるだけ買う
    if mon > cur:
      cnt = mon//cur
      mon = mon%cur
  #値が下がる前に売却
  elif cur > sec:
    mon += cur * cnt
    cnt = 0
  cur = sec
if cnt > 0:
  mon += A[-1]*cnt
print(mon)

Submission status: Accepted

Solution code:
n = int(input())

a_list = list(map(int, input().split()))
dp_list = [0]*n
dp_list[0] = 1000
for i in range(1,n):
    dp_list[i] = dp_list[i-1]
    for j in range(i):
        v = int(dp_list[j]/a_list[j])
        w = dp_list[j] + (a_list[i] - a_list[j]) * v
        dp_list[i] = max(dp_list[i],w)

print(dp_list[n-1])

Submission status: Accepted

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

money = 1000
stock = 0
for i in range(n):
    # 売る
    money += stock * a[i]
    stock = 0

    # 買う
    if i != n - 1 and a[i] < a[i + 1]:
        stock = money // a[i]
        money %= a[i]

print(money)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(x) for x in input().rstrip().split()]
now=1000
cnt=0
flag=0

for i in range(n-1):
    if flag==1:
        now+=cnt*a[i]
        cnt=0
        flag=0
        if a[i]<a[i+1]:
            cnt=now//a[i]
            now=now-cnt*a[i]
            flag=1
            continue


    if a[i]<a[i+1]:
        cnt=now//a[i]
        now=now-cnt*a[i]
        flag=1

if flag==1:
    now+=cnt*a[n-1]
print(now)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
kane=1000
#Nが所持金、Aが株価
#最初は、とりあえず最安値で購入（単価が上がる直前までの最小値）。その後は最高値で売（単価が下がる直前までの最大値）
mini=A[0]
maxi=0
jyoutai="buy"
num=0
#株だけ持ったままま、売却条件を満たさず最後まで行ってしまったとき→NG。買うときは、買値より高い値が今後存在しうるときのみにする
#購入条件を満たさず、買わないで最後まで行ってしまったとき→これはOK。最終的な利益は最大だから
for i in range(1,N):
    #購入時
    if jyoutai=="buy":
        if A[i]<mini:#最小値を更新
            mini=A[i]
        elif A[i]==mini and num>0:#株を持っていて値段が変わらないとき
            pass
        #elif A[i]>=mini and num==0 and A[i]<max(A[i+1:]):#最小値を更新しない&株を持っていない＆売れる見込みがあるなら購入
        elif A[i]>=mini and num==0:#最小値を更新しない&株を持っていないなら購入
            num=kane//mini
            kane=kane%mini
            jyoutai="sell"
            maxi=A[i]
        #もし最後に、
    #売却時
    elif jyoutai=="sell":
        if A[i]>maxi:#最大値を更新
            maxi=A[i]
        elif A[i]==maxi and num==0:#株を持っていなくて値段が変わらないとき
            pass
        elif A[i]<=maxi and num>0:#最大値を更新しない&株を持っている売却
            kane+=num*maxi
            num=0
            jyoutai="buy"
            mini=A[i]
if num>0:
    kane+=num*maxi
print(kane)

Submission status: Accepted

Solution code:
N=int(input())
ls=[int(s) for s in input().split()]
money=1000
stock=0
for i in range(N-1):
  if ls[i]<ls[i+1]:
    s=money//ls[i]
    money-=s*ls[i]
    stock+=s
  elif ls[i]>ls[i+1]:
    money+=ls[i]*stock
    stock=0
money+=ls[N-1]*stock

print(money)

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
money = 1000
kabu = 0
for i in range(1,n):
    if A[i-1] < A[i]:
        kabu = money // A[i-1]
        money -= kabu * A[i-1]
        money += kabu * A[i]
        kabu = 0
    #print(money,kabu)
print(money)

Submission status: Accepted

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

for i in range(1, N):
    if A[i] > A[i - 1]:
        p = p // A[i - 1] * A[i] + p % A[i - 1]

print(p)

Submission status: Accepted

Solution code:
n = int(input())
A = [*map(int, input().split())] + [0]
yen, stock = 1000, 0
now = A[0]
for nxt in A[1:]:
    if now < nxt:
        stock += yen // now
        yen -= yen // now * now
    else:
        yen += stock * now
        stock = 0
    now = nxt
print(yen + stock * now)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
b = 0
c = 1000
for i in range(n-1):
    if a[i] < a[i+1]:
        d = c // a[i]
        b += d
        c -= d * a[i]
    elif a[i] > a[i+1]:
        c += b * a[i]
        b = 0
if b > 0:
    c += a[-1] * b
print(c)

Submission status: Accepted

Solution code:
n = int(input())
A = [*map(int, input().split())] + [0]
yen, stock = 1000, 0
nxt = A[0]
for now in A[1:]:
    now, nxt = nxt, now
    if now < nxt:
        stock += yen // now
        yen -= yen // now * now
    else:
        yen += stock * now
        stock = 0
print(yen + stock * nxt)

Submission status: Accepted

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

yen = 1000
stocks = 0

for i in range(N):
  if i == N-1:
    yen += stocks * A[i]
    stocks = 0
    break
  
  if A[i] > A[i+1]:
    # sell everything
    yen += stocks * A[i]
    stocks = 0
  else:
    # buy everything
    num = yen // A[i]
    stocks += num
    yen -= A[i] * num

print(yen)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    okane = 1000

    for a, b in zip(A, A[1:]):
        if a <= b:
            q, r = divmod(okane, a)
            okane = q * b + r

    print(okane)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

curr = 1000
stock = 0

for i in range(n - 1):
    if ls[i] < ls[i + 1] and curr >= ls[i]:
        stock += curr // ls[i]
        curr -= stock * ls[i]
    elif ls[i] > ls[i + 1]:
        curr += stock * ls[i]
        stock = 0 

curr += stock * ls[i + 1]
stock = 0

print(curr)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7



n = I()
A = LI()
dp = [-INF] * n
dp[0] = 1000
for i in range(1, n):
    ret = dp[i - 1]
    for j in range(i):
        ret = max(dp[j] // A[j] * A[i] + dp[j] % A[j], ret)
    dp[i] = ret


print(dp[n - 1])

Submission status: Accepted

Solution code:
N=int(input())
A=[0]*N
A=list(map(int,input().split()))
money=1000
money_temp=1000
kazu=0
ma=0
mi=float('inf')
stop=0
for i in range(0,N-1):
    money=money+A[i]*kazu
    kazu=0
    if(A[i]<A[i+1]):
        kazu=money//A[i]
        money=money-A[i]*kazu

    elif(A[i+1]<=A[i]):
        pass

money=money+A[N-1]*kazu
print(money)

Submission status: Accepted

Solution code:
def 買う(株, 金, 株価):
    買う株 = 金 // 株価
    金 = 金 - 買う株*株価
    株 += 買う株
    return 株, 金

def 売る(株, 金, 株価):
    金 = 金 + 株*株価
    株 = 0
    return 株, 金

n = int(input())
株価 = [int(i) for i in input().split()]
株価.append(-1)

株 = 0
金 = 1000

for i in range(n):
    if 株価[i] < 株価[i+1]:
        株, 金 = 買う(株, 金, 株価[i])
    else:
        株, 金 = 売る(株, 金, 株価[i])

print(金)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N=int(input())
    A=[int(_) for _ in input().split()]
    M=1000
    for i in range(N-1):
        stock = 0
        if A[i]<A[i+1]:
            stock=M//A[i]
        M+=(A[i+1]-A[i])*stock
    print(M)

main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

    dp = [0]*(N+1)
    dp[0] = 1000
    for i in range(1, N+1):
        for j in range(0, i-1):
            # j日目に買ってi日目に売る
            m = A[j]
            for k in range(j, i-1):
                m = min(m, A[k])
            dp[i] = max(dp[i], dp[j]//m * A[i-1] + dp[j] % m)
        dp[i] = max(dp[i], dp[i-1])

    print(dp[N])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
a.append(0)
x,y=1000,0
for i in range(n):
    if a[i]>=a[i+1]:
        x+=y*a[i]
        y=0
    else:
        y+=x//a[i]
        x=x%a[i]
print(x)

Submission status: Accepted

Solution code:
#bottomかtopか
n=int(input())
a=list(map(int,input().split()))
an=[]
for i in range(1,n):
    if a[i]>a[i-1]:
        an.append(a[i-1])
        if i==n-1:
            an.append(a[i])
        break
pm=0
for j in range(i+1,n):
    #print(pm)
    if pm==0:
        if a[j]>=a[j-1]:
            if j==n-1:
                an.append(a[j])
            continue
        else:
            an.append(a[j-1])
            pm=1
    else:
        if a[j]<=a[j-1]:
            continue
        else:
            an.append(a[j-1])
            pm=0
            if j==n-1:
                an.append(a[j])
#print(an)
ans=1000
k=0
for i in range(len(an)):
    if i%2==0:
        k=ans//an[i]
        ans-=k*an[i]
    else:
        ans+=k*an[i]
        k=0
print(ans)

Submission status: Accepted

Solution code:
days = int(input())
vals = [int(x) for x in input().split()]
has = 1000
for i in range(days - 1):
    if vals[i] <= vals[i+1]:
        can, has = divmod(has, vals[i])
        has += can * (vals[i+1])
print(has)

Submission status: Accepted

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

    dp = [0]*(N+1)
    dp[0] = 1000
    for i in range(1, N+1):
        for j in range(0, i-1):
            # j日目に買ってi日目に売る
            dp[i] = max(dp[i], dp[j]//A[j] * A[i-1] + dp[j] % A[j])
        dp[i] = max(dp[i], dp[i-1])

    print(dp[N])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
given_A = list(map(int, input().split()))
A = []
for kabuka in given_A:
    if len(A) > 0 and kabuka == A[-1]:
        continue
    else:
        A.append(kabuka)

# 株価が全て同じ時のコーナーケース
if len(A) == 1:
    print(1000)
    exit()

money = 1000
stock = 0
n = len(A)
for i in range(len(A)):
    if i == 0:
        if A[i] < A[i + 1]:
            stock = money // A[i]
            money = money % A[i]
    elif i == n - 1:        
        if A[i - 1] < A[i]:
            money += stock*A[i]
            stock = 0
    else:
        if (A[i - 1] < A[i]) & (A[i] > A[i + 1]):
            money += stock*A[i]
            stock = 0
        elif (A[i - 1] > A[i]) & (A[i] < A[i + 1]):
            stock = money // A[i]
            money = money % A[i]
print(money)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
a.append(0)
x,y=1000,0
for i in range(n):
    if a[i]>a[i+1]:
        x+=y*a[i]
        y=0
    else:
        y+=x//a[i]
        x=x%a[i]
print(x+y*a[-2])

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

ans = 1000
dp = [-1 for i in range(N)]
dp[0] = 1000

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

Submission status: Accepted

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

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

print(CurrentMoney)

Submission status: Accepted

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

    money = 1000
    for i in range(1, N):
        if A[i-1] < A[i]:
            v = money//A[i-1]  # 株数
            money %= A[i-1]  # money -= v*A[i-1]
            money += v*A[i]
    print(money)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Y = [1000] * N

for i in range(N):
    a = A[i]
    y = Y[i]
    n = y//a
    for j in range(i+1,N):
        b = A[j]
        Y[j] = max(Y[j],y + (b-a)*n,y)

print(Y[-1])

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

yen=1000

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