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:
n = int(input())
a = list(map(int, input().split()))
money  = 1000
stock = 0
min_price = a[0]
max_price = a[0]
is_first_time_of_drop = False
for i in range(1, n):
    if a[i] > max_price:
        max_price = a[i]
        is_first_time_of_drop = True
        if i == n - 1:
            money = (money // min_price) * max_price + money % min_price
    elif a[i] == max_price:
        if i == n - 1:
            money = (money // min_price) * max_price + money % min_price
        continue
    else:
        if is_first_time_of_drop:
            money = (money // min_price) * max_price + money % min_price
            min_price = a[i]
            max_price = a[i]
            is_first_time_of_drop = False
        else:
            if a[i] < min_price:
                min_price = a[i]
                max_price = a[i]
            elif a[i] == min_price:
                continue
            else:
                is_first_time_of_drop = True
print(money)

Submission status: Accepted

Solution code:
a = int(input())
b = list(map(int, input().split()))
d = 0
c = 1000

while d+1 < a:
   if b[d+1] > b[d]:
       c = c - (b[d] * (c//b[d])) + ((c//b[d]) * (b[d+1]))
   else: pass
   d += 1

print(c)

Submission status: Accepted

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

money = 1000
stack = 0

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

Submission status: Accepted

Solution code:
def laod_to_mill():
    days = int(input())
    prices = tuple(map(int, input().split()))

    total = 1000
    ks = 0

    for d in range(days):
        if d == days - 1:
            total += ks * prices[d]
            break

        if prices[d] < prices[d + 1]:
            buy = total // prices[d]
            total -= buy * prices[d]
            ks += buy

        elif prices[d] > prices[d + 1]:
            total += ks * prices[d]
            ks = 0

    print(total)

def main():
    laod_to_mill()


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    n=int(input())
    A=tuple(map(int,input().split()))
    ans=1000
    num=0
    for i in range(n-1):
        ans+=num*A[i]
        num=0
        if A[i]<A[i+1]:
            num=ans//A[i]
            ans%=A[i]
    ans+=num*A[-1]
    print(ans)
    
if __name__=='__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

dp = [1000]

for i in range(1,n):
	maxdp = max(dp)
	kabu = max([ m%a[j] + (a[i]*(m // a[j]) ) for j, m in enumerate(dp) ] )
	dp.append( max( maxdp, kabu ) ) 
print(dp[-1])

Submission status: Accepted

Solution code:
n = int(input())
a = 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)

Submission status: Accepted

Solution code:
#import 
#=input()
n=int(input())
#=map(int,input().split())
a=list(map(int,input().split()))
#=[list(map(int,input().split())) for _ in range()]

l = [[a[0]]]
for i in range(n-1):
    if a[i] > a[i+1]:
        if a[i] != l[-1][0]:
            l[-1] += [a[i]]
        else:
            del l[-1]
        l += [[a[i+1]]]
if a[-1] != l[-1][0]:
    l[-1] += [a[-1]]
else:
    del l[-1]

m = 1000
for i in range(len(l)):
    k = m // l[i][0]
    m %= l[i][0]
    m += k * l[i][1]
print(m)

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:
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N=ii()
    _A=list(mi())
    A = []

    for a in _A:
        if len(A) > 0 and A[-1] == a: continue
        A.append(a)
    
    N = len(A)
    bottoms = []
    
    if N < 2:
        print(1000)
        exit()

    if A[0] < A[1]:
        bottoms.append(0)

    for i in range(N-1):
        if not i+2 < len(A): continue
        # print(A[i], A[i+1], A[i+2])
        if A[i] > A[i+1] and A[i+1] < A[i+2]:
            bottoms.append(i+1)
    
    money = 1000
    kabu = 0
    # print(bottoms)
    for bi in bottoms:
        bottom = A[bi]
        i = bi
        while i < N-1 and A[i] < A[i+1]:
            i += 1
        
        top = A[i]

        # print(bi,i)
        # print(bottom,top)
        kabu += money//bottom
        money -= money//bottom * bottom
        
        money += kabu * top
        kabu = 0
        # print("money",money)
    
    print(money)

    

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):
    if i == N - 1:
        money += stock * A[i]
        break
    if A[i] < A[i + 1]:
        stock += money // A[i]
        money %= A[i]
    elif A[i] > A[i + 1]:
        money += A[i] * stock
        stock = 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):
    if i == N - 1:
        money += stock * A[i]
        break
    if A[i] < A[i + 1]:
        buy_stock = money // A[i]
        money -= A[i] * buy_stock
        stock += buy_stock
    elif A[i] > A[i + 1]:
        money += A[i] * stock
        stock = 0

print(money)

Submission status: Accepted

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

money = 1000
stock = 0
cnt = 0
buy = True    

while True:
    if buy == False:
        while True:
            if cnt >= N-1:
                break
            if A[cnt+1] < A[cnt]:
                break
            cnt += 1
        if cnt >= N-1:
            break
        buy = True
        money += (stock*A[cnt])
        stock = 0
    else:
        while True:
            if cnt >= N-1:
                break
            if A[cnt+1] > A[cnt]:
                break
            cnt += 1
        if cnt >= N-1:
            break
        buy = False
        stock += (money//A[cnt])
        money %= A[cnt]
    if cnt >= N-1:
        break
money += (stock*A[-1])
print(max(money,1000))

Submission status: Accepted

Solution code:
N = int(input())
valls = list(map(int,input().split()))
 
money = 1000
have = 0

for i in range(N-1):
    if valls[i] < valls[i+1]:   
        have += money // valls[i]
        money = money % valls[i]
    elif valls[i] > valls[i+1]:
        money = money + have*valls[i]
        have = 0

money = money + have*valls[-1]
print(money)

Submission status: Accepted

Solution code:
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
import math
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math as M
MOD=10**9+7
import sys
#####################################
n=int(input())
A=INPUT()
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()]

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

Submission status: Accepted

Solution code:
N, *A = map(int, open(0).read().split())

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

print(m)

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int, input().split()))
cash = 1000
stock = 0
c = 0
for i in l:
  #print(cash, stock, i)
  if c==len(l)-1:
    cash+=stock*i
    stock = 0
  elif l[c]==l[c+1]:
    c+=1
    continue
  elif l[c]>l[c+1] and stock>0:
    cash+=stock*l[c]
    stock = 0
  elif l[c]<l[c+1] and stock==0:
    stock = cash//i
    cash = cash-(stock*i)
  c+=1
#print(cash, stock, i)
print(cash)

Submission status: Accepted

Solution code:
from itertools import groupby
n = int(input())
A = list(map(int, input().split()))

A = groupby(A)
G = []
for i, _ in A:
    G.append(i)

p = 1000
for i in range(len(G)-1):
    if G[i] < G[i+1]:
        tmp1 = p // G[i]
        tmp2 = p % G[i]
        p = tmp1 * G[i+1] + tmp2

print(p)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

syozi = 1000
kabu = 0

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

syozi += A[-1] * kabu

print(syozi)

Submission status: Accepted

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

#hoge日めにhoge枚の株券持ち
dp = [-7 for _ in range(n+1)]

dp[0] = 1000

#　i日目の所持金
for i in range(1,n+1):
    dp[i] = dp[i-1]
    for j in range(i):
        buy = dp[j]//l[j]
        tmp = dp[j]%l[j] + buy*l[i-1]
        dp[i] = max(dp[i], tmp)

print(dp[n])

Submission status: Accepted

Solution code:
import collections
N=int(input())
A=list(map(int,input().split()))
i=0
A.insert(0,float("inf"))
#print(A)
buy=[0]*N
sell=[0]*N
for i in range(N-1):
    if (A[i]>=A[i+1])and(A[i+2]>=A[i+1]):
        buy[i]=1
    if (A[i]<=A[i+1])and(A[i+2]<=A[i+1]):
        sell[i]=1
kabu=0
money=1000
#print(buy,sell)
#print(money,kabu)
A=A[1:]
#print(A)
for i in range(N):

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

    if sell[i]==1:
        money=money+kabu*A[i]
        kabu=0

    #print(money,kabu,A[i])
    #input()
#print(money,kabu)
money=money+kabu*A[N-1]
print(money)

Submission status: Accepted

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


if __name__ == "__main__":
    solve()

Submission status: Accepted

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


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
n = int(input().strip())
a = list(map(int, input().strip().split()))
b=[0]*n
for i in range(0,n-1):
    b[i]=a[i+1]/a[i]
money=1000
for i in range(n):
    if b[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()))
dp = [0] * n
dp[0] = 1000
for i in range(1, n):
  dp[i] = max(dp[i-1], dp[i-1] // a[i-1] * a[i] + dp[i-1] % a[i-1])
print(dp[-1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
arr = list(map(int,input().split()))
total = 1000
for i in range(n-1):
    if arr[i] < arr[i+1]:
        stocks = total // arr[i]
        total += (arr[i+1] - arr[i]) * stocks
print(total)

Submission status: Accepted

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

money = 1000
ticket = 0
for i in range(N - 1):
    # buy
    if A[i] < A[i + 1]:
        ticket += money // A[i]
        money -= (money // A[i]) * A[i]
    elif A[i] == A[i + 1]:
        pass
    # sell
    else:
        money += A[i] * ticket
        ticket = 0

money += A[-1] * ticket

print(money)

Submission status: Accepted

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

yen = 1000
kabu_yen = 0
kabu_n = 0
last_buy = -1
for i in range(1,n+1):
    if A[i-1] < A[i]: # buy : after up
        tanka = A[i-1]
        m = yen // tanka
        cost = tanka * m
        yen -= cost
        kabu_yen += cost
        kabu_n += m

    elif A[i-1] > A[i]: # sell: after down
        yen += A[i-1] * kabu_n
        kabu_yen = 0
        kabu_n = 0

print(yen)

Submission status: Accepted

Solution code:
# 初期入力
from statistics import mean, median,variance,stdev
import sys
input = sys.stdin.readline  #文字列では使わない
N = int(input())
A = list(map(int, input().split()))
monney =[-1]*N
kabu_med =median(A)
kabu_num =[-1]*N

#初日
if A[0] < A[1]:
    kabu_num[0]   = 0     +1000 //A[0]
    monney[0]     = 1000  -kabu_num[0] *A[0]
elif A[0] >= A[1]:
    kabu_num[0]   = 0
    monney[0]     = 1000
#2日目～ラス前
for i in range(1,N-1):
    if A[i-1] >= A[i] < A[i+1]:
        kabu_num_today =monney[i-1] //A[i]
        kabu_num[i]   = kabu_num[i-1]   +kabu_num_today
        monney[i]     = monney[i-1]     -kabu_num_today *A[i]
    elif A[i-1] <= A[i] > A[i+1]:
        kabu_num_today =kabu_num[i-1]
        kabu_num[i]   = 0
        monney[i]     = monney[i-1]     +kabu_num_today *A[i]
    elif A[i-1] <= A[i] <= A[i+1]:
        kabu_num[i]   = kabu_num[i-1]
        monney[i]     = monney[i-1]
    elif A[i-1] >= A[i] >= A[i+1]:
        kabu_num[i]   = kabu_num[i-1]
        monney[i]     = monney[i-1]

#最終日
monney[N-1] =monney[N-2]     +kabu_num[N-2] *A[N-1]

print(monney[-1])

Submission status: Accepted

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

print(money)

Submission status: Accepted

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

wallet = 1000

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

print(wallet)

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

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

shojikin = 1000
stock = 0
for i in range(N):
    if stock:
        shojikin += stock * A[i]
        stock = 0
    if i+1 < N:
        if A[i] < A[i+1]:
            q, mod = divmod(shojikin, A[i])
            stock = q
            shojikin = mod

print(shojikin)

Submission status: Accepted

Solution code:
N, *A = map(int, open(0).read().split())

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

print(cur)

Submission status: Accepted

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


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
#!/usr/bin python3
# -*- coding: utf-8 -*-

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

Submission status: Accepted

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

money=1000
kabu=0
for i in range(N-1):
  if alist[i]<alist[i+1]:
    #buy as possible
    k=money//alist[i]
    kabu+=k
    money-=k*alist[i]
  elif alist[i]>alist[i+1]:
    #sell all
    money+=alist[i]*kabu
    kabu=0

money+=alist[N-1]*kabu    
print(money)

Submission status: Accepted

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

high = 1000
kabu = 1000 // A[0]
amar = 1000 - kabu * A[0]

for i in range(1, N):
    res = amar + kabu * A[i]
    if res > high:
        high = res
    if A[i] < max(A[i:]):
        kabu = high // A[i]
        amar = high - kabu * A[i]
    
print(high)

Submission status: Accepted

Solution code:

N = int(input())
X = 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):
        n = dp[j] // X[j]
        dp[i] = max(dp[i], dp[j] + (X[i] - X[j]) * n)

print(dp[-1])

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]=max(dp[i-1],dp[i-1]//A[i-1]*A[i]+dp[i-1]%A[i-1])
print(dp[-1])

Submission status: Accepted

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

Submission status: Accepted

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

M = 1000
K = 0

# 0: nothing, 1:buy, 2:sell
flgs = [0] * N
for i in range(N-1):
    if i == 0:
        if A[i] < A[i+1]:
            flgs[i] = 1
        continue
    if A[i] < A[i+1]:
        flgs[i] = 1
    else:
        flgs[i] = 2
flgs[N-1] = 2

for i in range(N):
    flg = flgs[i]
    if flg == 1:
        K += M // A[i]
        M = M % A[i]
    elif flg == 2:
        M += A[i] * K
        K = 0

print(M)

Submission status: Accepted

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

def main():
    money = 1000
    n = 0
    
    for i in range(1, len(a)):
        if (a[i-1] < a[i]):   # 買う
            n = money // a[i-1]
            money += (a[i] - a[i-1]) * n

    print(money)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ma = lambda :map(int,input().split())
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
n = ni()
A = list(ma())
tot = 1000
kab = 0
for i in range(n-1):
    tot += A[i]*kab
    kab = 0
    if A[i] > A[i+1]:
        pass
    if A[i] <= A[i+1]:#価値が上がるなら
         kab,tot = divmod(tot,A[i])
tot+=A[-1]*kab
print(tot)

Submission status: Accepted

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

    dp = [-float('inf')] * N
    dp[0] = 1000

    for i in range(1,N):
        dp[i] = dp[i-1]
        for j in range(i):
            n_stock = dp[j] // A[j]
            n_money = n_stock * A[i] + dp[j] % A[j]
            dp[i] = max(dp[i], n_money)
    
    print(dp[-1])
        
if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:

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

cur = 1000
for i in range(N - 1):
    if X[i] < X[i + 1]:
        stocks = cur // X[i]
    else:
        stocks = 0

    cur += (X[i + 1] - X[i]) * stocks

# Last
print(cur)

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    A = [int(x) for x in input().split()]
    C = 1000
    for i in range(N - 1):
        if A[i] < A[i + 1]:
            b = C // A[i]
            # print(b)
            C -= A[i] * b
            # print(C)
            C += A[i + 1] * b
            # print(C)
    print(C)


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
def unique(list_to_unique) -> list:
    if len(list_to_unique) == 0:
        return []
    else:
        result = [list_to_unique[0]]
        for it in range(1, len(list_to_unique)):
            if list_to_unique[it] != list_to_unique[it - 1]:
                result.append(list_to_unique[it])
        return result


n = int(input())
a = list(map(int, input().split()))
a = unique(a)
while len(a) > 1 and a[0] >= a[1]:
    a.pop(0)
while len(a) > 1 and a[len(a) - 1] <= a[len(a) - 2]:
    a.pop(len(a) - 1)
b = []
na = []
for i in range(len(a)):
    if i == 0 or i == len(a) - 1:
        b.append(a[i])
    elif a[i] > a[i - 1] and a[i] > a[i + 1] or a[i] < a[i + 1] and a[i] < a[i - 1]:
        b.append(a[i])
a = b
if len(a) > 2:
    money = 1000
    stocks = 0
    for i in range(len(a)):
        if i % 2 == 1:
            money += stocks * a[i]
            stocks = 0
        else:
            stocks += money // a[i]
            money %= a[i]
    print(money)
elif len(a) == 2 and a[0] < a[1]:
    print(1000 // a[0] * a[1] + 1000 % a[0])
else:
    print(1000)

Submission status: Accepted

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

am = 1000
st = 0
for a1, a2 in zip(an, an[1:]):
    am += a1 * st
    st = 0
    if a1 < a2:
        st, am = divmod(am, a1)

am += an[-1] * st
print(am)

Submission status: Accepted

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

k_y = [1000]
yen = 1000
resyen = 1000
kabu_max = 0
for i in range(n):
	#株を売り払うケース
	newyen = max( yen, kabu_max * a[i] + resyen)
	
	#株を最大買うケース
	kabu_max_new = max( kabu_max + resyen // a[i], yen // a[i] )
	if kabu_max_new == yen // a[i]:
		if kabu_max_new == kabu_max + resyen // a[i]:
			resyen = max( yen % a[i], resyen % a[i])
		else:
			resyen = yen % a[i]
	
	yen = newyen
	kabu_max = kabu_max_new
	#print(kabu_max,yen,resyen)
print( yen )

Submission status: Accepted

Solution code:
N = int(input())
s_list = list(input().split())
money = 1000
stock = 0

for i in range(N):
  #print("i:{}".format(i))

  # Last day
  if (i == N-1):
    money += stock * int(s_list[i])
    stock = 0
    break

  # Stock price tomorrow is higher than today
  if (int(s_list[i+1]) > int(s_list[i])):
    stock = stock + int(money / int(s_list[i]))
    money = money - (int(s_list[i]) * int(money / int(s_list[i])))
    continue

  # Stock price tomorrow is lower than or equal to today
  if (int(s_list[i+1]) <= int(s_list[i])):
    money = money + (int(s_list[i]) * stock)
    stock = 0
    continue

print(money)

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
        s += m // a_cur
        m -= m // a_cur * a_cur
    else:
        # sell
        m += s * a_cur
        s = 0
    a_cur = a_next
m += s * a_cur
print(m)

Submission status: Accepted

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

stock=0
money=1000

for i in range(1,N):
    #上がってたら前日の価格との差分を毎日もらう
    if A[i-1] < A[i]:
        money=money+ (A[i]-A[i-1]) * (money//A[i-1]) 
print(money)

Submission status: Accepted

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

A.append(0)
money = 1000

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

print(money)

Submission status: Accepted

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

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

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
        s += m // a_cur
        m -= m // a_cur * a_cur
    else:
        # sell
        m += s * a_cur
        s = 0
    a_cur = a_next
m += s * a_cur
print(m)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = 1000
for i in range(len(A) - 1):
    stocks = 0
    if A[i] < A[i + 1]:
        stocks = ans // A[i]
        ans += (A[i + 1] - A[i]) * stocks
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 a[i]<a[i+1]:
    if money<a[i]:
      continue
    kabu=money//a[i]
    money=money-a[i]*kabu
  elif a[i]==a[i+1]:
    pass
  else:
    money=money+a[i]*kabu
    kabu=0
money=money+a[-1]*kabu

print(money)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

money = 1000

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

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):
    dp[i] = dp[i-1]
    for j in range(1,i):
        dp[i] = max(dp[i], dp[j] // A[j-1] * A[i-1] + (dp[j] % A[j-1]))

print(dp[-1])

Submission status: Accepted

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

Submission status: Accepted

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

A.append(0)

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

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import math
def gcd(a,b):
    return b if not a%b else gcd(b,a%b)
def lcm(a,b):
    return (a*b)//gcd(a,b)

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

if __name__ == '__main__':
    main()

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

print(money)

Submission status: Accepted

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

now = 1000

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

print(now)

Submission status: Accepted

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

dp = [1000]*(N+1)

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