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:
#関数リスト
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n = I()
mylist = LI()
buy = [0] * n

katamuki = 0
for i in range(n-1):
    if katamuki == 0:
        if mylist[i+1] > mylist[i]:
            buy[i] = "buy"
            katamuki = 1
        elif mylist[i+1] < mylist[i]:
            katamuki = -1
    elif katamuki == -1 and mylist[i+1] > mylist[i]:
        buy[i] = "buy"
        katamuki = 1
    elif katamuki == 1 and mylist[i+1] < mylist[i]:
        buy[i] = "sell"
    elif katamuki == 1 and mylist[i+1] > mylist[i]:
        buy[i] = "buysell"

        
result = 1000
stock = 0
price = 0    
for i in range(n):
    if buy[i] == "buy":
        stock = result // mylist[i]
        result -= mylist[i] * stock
    elif buy[i] == "sell":
        result += mylist[i] * stock
        stock = 0
    elif buy[i] == "buysell":
        result += mylist[i] * stock
        stock = result // mylist[i]
        result -= mylist[i] * stock
    elif i == n-1:
        result += mylist[i] * stock
print(result)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(4100000)

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

dp = [-1] * 81
dp[0] = 1000

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

print(dp[N - 1])

Submission status: Accepted

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

print(m)

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
A = np.array(input().split(), dtype=np.int64)
money = 1000
kabu = 0

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

Submission status: Accepted

Solution code:
_,a=open(0)
*a,=map(int,a.split())
x=1000
for i,j in zip(a,a[1:]):x+=x//i*(j-i)*(i<j)
print(x)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
money = [[1000, 0]]
ans = 1000
B = [1 for _ in range(N)] #-1 -> buy 1 ->sell 0 -> nothing
for k in range(N-1):
  if A[k] < A[k+1]:
    B[k] = -1
  elif A[k] == A[k+1]:
    B[k] = 0

for k in range(N):
  if B[k] == -1:
    new = []
    for j in range(len(money)):
      if A[k] <= money[j][0]:
        new.append([money[j][0]%A[k], money[j][1] + money[j][0]//A[k]])
    money += new
  
  if B[k] == 1:
    ans = 0
    for j in range(len(money)):
      ans = max(money[j][0] + money[j][1]*A[k], ans)
    money[0] = [ans, 0]

print(ans)

Submission status: Accepted

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

M = 1000
X = 0

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

print(int(M))

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    last = a[0]
    money = 1000
    kabu = 0
    for i, kabuka in enumerate(a):
        if i == len(a)-1:
            break
        if a[i+1] > a[i]:
            kabu = money//a[i]
            money += (a[i+1] - a[i]) * kabu
    print(money)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
x=1000
for a,b in zip(a:=[*map(int,[*open(0)][1].split())],a[1:]):x+=x//a*(b-a)*(a<b)
print(x)

Submission status: Accepted

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

now = 1000
for a_pre, a in zip(A, A[1:]):
    if a > a_pre:
        n = now // a_pre
        now = (now%a_pre) + a*n

print(now)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

rlt = 1000
for i in range(N-1):
  if As[i+1] > As[i]:
    rlt = (As[i+1]-As[i])*(rlt//As[i]) + rlt
    
print(rlt)

Submission status: Accepted

Solution code:
# coding: utf-8


def solve(*args: str) -> str:
    n = int(args[0])
    A = list(map(int, args[1].split()))
    budget = 1000
    stock = 0

    for i in range(n-1):
        if A[i] < A[i+1] and A[i] <= budget:
            stock, budget = divmod(budget, A[i])
        elif A[i+1] < A[i]:
            budget += A[i]*stock
            stock = 0

    return str(A[-1]*stock+budget)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Submission status: Accepted

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

money = 1000
stock = 0

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

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

Submission status: Accepted

Solution code:
n = int(input())
al = [int(i) for i in input().split()]

mn = 201
money = 1000

for a in al:
    if a < mn:
        mn = a
    if a > mn:
        money = money-(money//mn*mn) + (money//mn)*a
        mn = a

print(money)

Submission status: Accepted

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

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

print(yen)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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=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]

    else :
        continue

print(money)

Submission status: Accepted

Solution code:
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') 
inf = float('inf') ;mod = 10**9+7 
mans = inf ;ans = 0 ;cnt = 0 ;pro = 1

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

Submission status: Accepted

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

    money = 1000

    low = A[0]
    p = A[0]
    for x in A:
        if p > x:
            money += (p - low) * (money // low)
            low = x
        p = x

    money += (p - low) * (money // low)

    print(money)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

m = 1000
s = 0

for i in range(1, n):
    a_next = a[i]
    if a_cur < a_next:
        # buy current and sell next
        s = m // a_cur
        m += s * (a_next - a_cur)
    a_cur = a_next
print(m)

Submission status: Accepted

Solution code:
n,*l=map(int,open(0).read().split())
a,c=1000,0
for i in range(n-1):
  s,t=l[i:i+2]
  if s>t: a+=c*s; c=0
  if s<t: c+=a//s; a-=a//s*s
print(a+c*t)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
m = 1000
s = 0
flag = "e"
idx = 0
for i in range(N-1):
  if A[i]<A[i+1] and (flag == "d" or flag == "e"):
    s += m//A[i]
    m = m%A[i]
    flag = "u"
  elif A[i]>A[i+1] and (flag == "u" or flag == "e"):
    m += s*A[i]
    s = 0
    idx = i
    flag = "d"
  elif A[i]==A[i+1]:
    flag = "e"
    
m += s*A[N-1]

print(int(m))

Submission status: Accepted

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N = I()
A = LI()

# 買った株は翌日全て売ってよい
# 貪欲に

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

Submission status: Accepted

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
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 S(): return input()
def LS(): return input().split()


INF = float('inf')

n = I()
a = LI()
ans = 1000
for i in range(n - 1):
    kabu = 0
    if a[i] < a[i+1]:
        # 出来るだけ買う
        kabu = ans // a[i]
    # 買った株があれば i + 1日目 に売る
    if kabu > 0:
        ans += (a[i + 1] - a[i]) * kabu
print(ans)

Submission status: Accepted

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

buy = 0
money = 1000
for i in range(N-1):
    if buy != 0:
        money += buy*A[i]
        buy = 0

    if A[i] < A[i+1]:
        buy = money // A[i]
        money -= buy * A[i]

if buy != 0:
    money += buy*A[-1]

print(money)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

money = 1000
kabu = 0

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

    else:
        if A[i] < A[i + 1]:
            kabu = money // A[i]
            money -= kabu * A[i]

if kabu != 0:
    money += kabu * A[len(A) - 1]
    
print(money)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

    money = 1000

    low = A[0]
    p = A[0]
    for x in A:
        if p > x:
            money += (p - low) * (money // low)
            low = x
        p = x

    money += max(0, p - low) * (money // low)

    print(money)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n = int(input())
    A = list(map(int, input().split()))
    currency = 1000
    stock = 0
    for i in range(n - 1):
        currency += A[i] * stock
        stock = 0
        if A[i + 1] > A[i]:
            stock, currency = divmod(currency, A[i])
    print(currency + A[-1] * stock)
resolve()

Submission status: Accepted

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

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

print(val)

Submission status: Accepted

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

b = []
left, right = 0, 1
while right != n + 2:
    if a[left:right] == list(sorted(a[left:right])):
        right += 1
    else:
        b.append(a[left:right - 1])
        left = right - 1

score = 1000
for a_lr in b:
    stock, score = divmod(score, a_lr[0])
    score += stock * a_lr[-1]
print(score)

Submission status: Accepted

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

cnt = 0
money = 1000
b = 0
for i in range(n-1):
    if cnt == 0 and A[i] < A[i+1]:
        cnt += money//A[i]
        money %= A[i]
        b = A[i]
    else:
        money += cnt * A[i]
        cnt = 0
        if A[i] < A[i+1]:
            cnt += money//A[i]
            money %= A[i]
if cnt > 0:
    money += cnt * max(A[-1], b)
print(money)

Submission status: Accepted

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

wallet = 1000
stock = 0

for i in range(N - 1):
    if A[i] < A[i + 1] and wallet > 0:  # 次値上がり and 金がある→買う
        action = wallet // A[i]
        if wallet >= action * A[i]:
            stock += wallet // A[i]
            wallet -= action * A[i]
    elif A[i] > A[i + 1] and stock > 0:  # 次値下がり and 株持っている→売り
        wallet += stock * A[i]
        stock = 0
    # print(i, wallet, stock)

# 最後残っていたら全部売る
wallet += stock * A[-1]

print(wallet)

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] and money != 0:
        kabu += money // a[i]
        money -= a[i] * (money // a[i])
    elif a[i] > a[i+1] and kabu != 0:
        money += a[i] * kabu
        kabu = 0
print(money + a[-1] * kabu)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
 
m = 1000
 
for a,b in zip(A,A[1:]):
    if a >= b: continue
    k,m = divmod(m,a)
    m += k*b
print(m)

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] and money != 0:
        kabu += money // a[i]
        money -= a[i] *(money // a[i])
    elif a[i] > a[i+1] and kabu != 0:
        money += a[i] * kabu
        kabu = 0
print(money + a[-1] * kabu)

Submission status: Accepted

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

ans = 1000
lastpay = -1
buy = True
stock = 0

buf = []
for i in range(N-1):
  if A[i+1]==A[i]:
    buf.append(0)
  elif A[i+1]>A[i]:
    buf.append(1)
  else:
    buf.append(-1)

for i in range(len(buf)):
  if buy:
    if i == 0 and buf[i]>0:
      buy = False
      dstock = ans//A[i]
      stock += dstock
      ans -= dstock*A[i]
      lastpay = dstock*A[i]
      #print(i,"buy")
    elif i>0 and buf[i]>0:
      buy = False
      dstock = ans//A[i]
      stock += dstock
      ans -= dstock*A[i]
      lastpay = dstock*A[i]
      #print(i, "buy")
    if i == N-2 and buf[i]>0:
       ans += stock*A[i+1]
        #print(i+1, "pay")
  else:
    if buf[i-1]>=0 and buf[i]<0:
      buy = True
      ans += stock*A[i]
      stock = 0
      #print(i, "pay")
    elif i == N-2 and buf[i]>=0:
      buy = True
      ans += stock*A[i+1]
      #print(i+1, "pay")
#print(buf)
print(ans)

Submission status: Accepted

Solution code:
import sys
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] and kabu == 0 :
    kabu = money // A[i]
    money = money - kabu*A[i]
  elif A[i] > A[i + 1] and kabu > 0:
    money = money + kabu*A[i]
    kabu = 0
    
if kabu > 0 :
  print(money + kabu*A[N-1])
else :
  print(money)

Submission status: Accepted

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

money=1000
kabu=0
for i in range(N):
    money=money+A[i]*kabu
    kabu=0

    if i!=(N-1):
        if A[i]<A[i+1]:
            kabu=money//A[i]
            money-=kabu*A[i]

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):
    if i == N-1:
        money += stock * A[i]
        break
    if A[i] < A[i+1]:
        tmp_stock = money // A[i]
        stock += tmp_stock
        money -= tmp_stock * A[i]
    elif A[i] > A[i+1]:
        money += stock * A[i]
        stock = 0
    else:
        pass
 
print(money)

Submission status: Accepted

Solution code:
N = int(input())
*A, = map(int, input().split())
money, stock = 1000, 0
for a, nxt in zip(A, A[1:]):
    money += stock * a
    stock = 0
    if a <= nxt:
        stock, money = divmod(money, a)
money += stock * A[-1]
print(money)

Submission status: Accepted

Solution code:
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 = list(map(int, input().split()))

stock = 1000

num = 0

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

print(stock+A[-1]*num)

Submission status: Accepted

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

a.append(90)
money=1000
kabu=0
for i in range(n):
  if a[i+1] > a[i]:
    kabu+=int(money/a[i])
    money-=a[i]*int(money/a[i])
  elif a[i+1] < a[i]:
    money+=kabu*a[i]
    kabu=0
print(money)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
# print('A:',A)
money=1000
kabu=0

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

print(money)

Submission status: Accepted

Solution code:
n = int(input())
stack = list(map(int,input().split()))
cnt = 1000
p = stack[0]
g = stack[0]
f = 0
for i in range(len(stack)):
    if stack[i] > g:
        g = stack[i]
        f = 1
        continue

    if stack[i] < g:
        itp = cnt // p
        cnt = cnt - (itp * p)
        cnt = cnt + (itp * g)
        p = stack[i]
        g = stack[i]
        f = 0

itp = cnt // p
cnt = cnt - (itp * p)
cnt = cnt + (itp * g)
print(cnt)

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]:
        diff = a[i] - a[i-1]
        stock = money // a[i-1]
        money += stock * diff
print(money)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
m = 1000
s = 0
idx = 0
for i in range(N-1):
  if A[i]<A[i+1]:
    s = m//A[i]
    m = m%A[i]

  m += s*A[i+1]
  s = 0

print(m)

Submission status: Accepted

Solution code:
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()

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]-A[i])
print(money)

Submission status: Accepted

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy

if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    have = 1000
    for i in range(n-1):
        kabu = 0
        if a[i] < a[i+1]:
            kabu = have//a[i]
        have += (a[i+1] - a[i])*kabu
    print(have)

Submission status: Accepted

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

s=1000

for i in range(n):
  if i==0:
    pass
  elif a[i]>a[i-1]:
    s=s+(s//a[i-1])*(a[i]-a[i-1])

print(s)

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

Submission status: Accepted

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

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

# 最後
i += 1
total += (kabu * A[i])
kabu = 0
print(total)

Submission status: Accepted

Solution code:
from bisect import bisect_right

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

    money = 1000
    stock = 0
    old_trend = 0
    trend = A[1] - A[0]
    buy_point = []
    bought_point = []

    for i in range(N-1):
        trend = A[i+1] - A[i]
        if trend * old_trend > 0 or trend == 0:
            continue
        else:
            if trend > 0:
                buy_point.append(i)
            if trend < 0:
                bought_point.append(i)
        old_trend = trend

    if len(buy_point) > len(bought_point):
        bought_point.append(N-1)

    for i in range(N):
        if i in buy_point:
            buy = money//A[i]
            stock += buy
            money -= buy*A[i]

        
        if i in bought_point:
            bought = stock
            stock = 0
            money += bought * A[i]
    print(money)
    


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
x.append(90)
y = 1000
k =0
for i in range(len(x)-1):
    if x[i] < x[i+1]:
        k += int(y/x[i])
        y -= x[i]*int(y/x[i])
    elif x[i] > x[i+1]:
        y += x[i]*k
        k = 0
    
print(y)

Submission status: Accepted

Solution code:
import sys
from collections import deque
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    N = readint()
    A = list(readnums())
    b = 1000
    s = 0
    for i in range(N - 1):
        if A[i] < A[i + 1]:
            s += b // A[i]
            b %= A[i]
        elif A[i] > A[i + 1]:
            b += A[i] * s
            s = 0

    if A[-1] >= A[-2]:
        b += A[-1] * s
        s = 0

    print(b)
    # d = deque(A)
    # d.appendleft(201)
    # d.append(0)
    # # ans = 1000 + (max(A) - min(A)) * (1000 // min(A))
    # il = []
    # for i in range(N):
    #     if d[i] <= d[i + 1] and d[i + 1] > d[i + 2]:
    #         il.append(i)
    #     elif d[i] >= d[i + 1] and d[i + 1] < d[i + 2]:
    #         il.append(i)

    # # print(il)
    # if len(il) <= 1:
    #     print(1000)
    # else:
    #     b = 1000
    #     s = 0
    #     if A[il[0]] < A[il[1]]:
    #         for i, v in enumerate(il):
    #             if not i % 2:
    #                 s += b // A[v]
    #                 b -= s * A[v]
    #             else:
    #                 b += s * A[v]
    #                 s = 0
    #             # print(b, s)
    #     else:
    #         for i, v in enumerate(il):
    #             if i % 2:
    #                 s += b // A[v]
    #                 b -= s * A[v]
    #             else:
    #                 b += s * A[v]
    #                 s = 0
    #             # print(b, s)
    #     if s:
    #         b = A[il[-1]] * s

    #     print(max(b, 1000))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

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]:
        pass
    else:
        T=ans//A[i]
        ans+=T*(A[i+1]-A[i])
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
from collections import deque
from collections import OrderedDict
import itertools
from sys import stdin
input = stdin.readline


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

  buy = []
  sell = []

  iflag = False
  if A[0] < A[1]:
    iflag = True
    buy.append(0)
  else:
    iflag = False

  for i in range(2, N):
    if iflag and A[i-1] < A[i]:
      iflag = True

    elif iflag and A[i-1] > A[i]:
      iflag = False
      sell.append(i-1)

    elif not(iflag) and A[i-1] < A[i]:
      iflag = True
      buy.append(i-1)

    elif not(iflag) and A[i-1] > A[i]:
      iflag = False

    else:
      continue

  if iflag:
    sell.append(N-1)

  # print(buy)
  # print(sell)

  m = 1000
  nstack = 0
  for i in range(N):
    if i in buy:
      nbuy = (m//A[i])
      m -= A[i]*nbuy
      nstack += nbuy
    if i in sell:
      m += A[i]*nstack
      nstack = 0
    # print(i, m, nstack)
  print(m)


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

Submission status: Accepted

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N = I()
B = [0] + LI()

A = [0]
for i in range(N):  # 要らないものを消す
    if B[i] != B[i+1]:
        A.append(B[i+1])

N = len(A)-1
MAX = [0,1000] + [0]*N  # MAX[i] = i日目開始時点の所持金の最大値

from functools import lru_cache

@lru_cache(maxsize=None)
def dfs(n,money):
    if n == N+1:
        return money
    else:
        res = money
        for i in range(n,N):  # 購入
            for j in range(i+1,N+1):  # 売却
                if A[i] == min(A[i:j+1]) and A[j] == max(A[i:j+1]) and A[i] < A[j]:
                    a = money+(A[j]-A[i])*(money//A[i])
                    if a > MAX[j+1]:
                        res = max(res,dfs(j+1,a))
                        MAX[j+1] = a
        return res

print(dfs(1,1000))

Submission status: Accepted

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
#======================================================#
def main():
    n = II()
    aa = MII()
    balance = 1000
    for i in range(n-1):
        if aa[i] < aa[i+1]:
            num = balance // aa[i]
            balance += num * (aa[i+1] - aa[i])
    print(balance)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

baibai = [] 
#1は買い時、-1は売り時、0は無視
for i in range(N):
    sa = A[i+1] -A[i]
    if sa == 0:
        baibai.append(0)
    elif sa != abs(sa):
        baibai.append(-1)
    else:
        baibai.append(1)


#baibai通りに売買(最後の売り時で打ち切り)
for j in range(N):
    if baibai[j] > 0:
        kabu += (kane//A[j])
        kane -= A[j] * (kane//A[j])
    elif baibai[j] < 0:
        kane += A[j] * kabu
        kabu = 0

print(kane)