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
for i in range(1, N):
    if A[i - 1] < A[i]:
        money = money % A[i - 1] + A[i] * (money // A[i - 1])
print(money)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n=int(input())
alist=list(map(int,input().split()))
m_p=alist[0]
money=int(1000%alist[0])
kabu=int(1000/alist[0])
for i in range(n):
  if m_p<alist[i]:
    m_p=alist[i]
    money+=kabu*m_p
  elif m_p>alist[i]:
    money+=kabu*m_p
    m_p=alist[i]
  else:
    continue
  kabu=int(money/m_p)
  money=int(money%m_p)
money+=kabu*m_p
print(money)

Submission status: Accepted

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

print(x)

Submission status: Accepted

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

money = money + A[N-1]*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-1):
  if A[i] < A[i+1]:
    mod,money = divmod(money , A[i])
    kabu += mod
  if A[i] > A[i+1]:
    money = money + A[i] * kabu
    kabu = 0

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

Submission status: Accepted

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

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

Submission status: Accepted

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

money=1000

chart=[a[0]]

for kabuka in a:
    if kabuka==chart[-1]:
        continue
    else:
        chart.append(kabuka)

days=len(chart)
kabu=0

if days==1:
    print(money)
    exit()

for i in range(days):
    if i==0:
        if chart[0]<chart[1]:
            kabu=money//chart[0]
            money%=chart[0]

    elif i==days-1:
        money+=kabu*chart[i]
        kanu=0
    
    else:
        if chart[i-1]<chart[i] and chart[i]>chart[i+1]:
            money+=kabu*chart[i]
            kabu=0

        if chart[i-1]>chart[i] and chart[i]<chart[i+1]:
            kabu=money//chart[i]
            money%=chart[i]

print(money)

Submission status: Accepted

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

def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    N = int(input())
    A = list(map(int, input().split()))

    return N, A

def main(N: int, A: list) -> None:
    """
    メイン処理.

    Args:\n
        N (int): 日数（2 <= N <= 80）
        A (list): i日目の株価（100 <= A_i <= 200）
    """
    # 求解処理
    dp = [-1 for n in range(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])

if __name__ == "__main__":
    # 標準入力を取得
    N, A = get_input()

    # メイン処理
    main(N, A)

Submission status: Accepted

Solution code:
import numpy as np

def buy_stock(have_money, have_stock, have_stock_valuation, stock_price):
    stock_num = have_money // stock_price
    have_money -= stock_num * stock_price
    have_stock += stock_num
    have_stock_valuation += stock_num * stock_price

    return have_money, have_stock, have_stock_valuation

def sell_stock(have_money, have_stock, have_stock_valuation, stock_price):
    have_money += have_stock * stock_price
    have_stock = 0
    have_stock_valuation = 0

    return have_money, have_stock, have_stock_valuation

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    A = np.array(A)
    have_money = 1000
    have_stock = 0
    have_stock_valuation = 0
    call_status = True

    for i in range(N):

            if call_status:
                if i == N - 1:
                    continue
                if A[i] < A[i+1]:
                    have_money, have_stock, have_stock_valuation = buy_stock(have_money, have_stock, have_stock_valuation, A[i])
                    call_status = False
                if not call_status:
                    if have_stock_valuation / have_stock < A[i]:
                        have_money, have_stock, have_stock_valuation = sell_stock(have_money, have_stock, have_stock_valuation,  A[i])
                        call_status = True
            else:
                if have_stock_valuation / have_stock < A[i]:
                    have_money, have_stock, have_stock_valuation = sell_stock(have_money, have_stock, have_stock_valuation,  A[i])
                    call_status = True
                if call_status:
                    if i == N - 1:
                        continue
                    if A[i] < A[i+1] and call_status:
                        have_money, have_stock, have_stock_valuation = buy_stock(have_money, have_stock, have_stock_valuation, A[i])
                        call_status = False
            
    print(have_money)

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
A = list(map(int, input().split()))
A = np.array(A)
have_money = 1000
have_stock = 0
have_stock_valuation = 0
call_status = True

def buy_stock(have_money, have_stock, have_stock_valuation, stock_price):
    stock_num = have_money // stock_price
    have_money -= stock_num * stock_price
    have_stock += stock_num
    have_stock_valuation += stock_num * stock_price

    return have_money, have_stock, have_stock_valuation

def sell_stock(have_money, have_stock, have_stock_valuation, stock_price):
    have_money += have_stock * stock_price
    have_stock = 0
    have_stock_valuation = 0

    return have_money, have_stock, have_stock_valuation

for i in range(N):

        if call_status:
            if i == N - 1:
                continue
            if A[i] < A[i+1]:
                have_money, have_stock, have_stock_valuation = buy_stock(have_money, have_stock, have_stock_valuation, A[i])
                call_status = False
            if not call_status:
                if have_stock_valuation / have_stock < A[i]:
                    have_money, have_stock, have_stock_valuation = sell_stock(have_money, have_stock, have_stock_valuation,  A[i])
                    call_status = True
        else:
            if have_stock_valuation / have_stock < A[i]:
                have_money, have_stock, have_stock_valuation = sell_stock(have_money, have_stock, have_stock_valuation,  A[i])
                call_status = True
            if call_status:
                if i == N - 1:
                    continue
                if A[i] < A[i+1] and call_status:
                    have_money, have_stock, have_stock_valuation = buy_stock(have_money, have_stock, have_stock_valuation, A[i])
                    call_status = False
        
print(have_money)

Submission status: Accepted

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

Mcashe = 1000
Mkabu = 0

for i in range(len(A) - 1):
    Mcashe += (Mkabu * A[i])
    Mkabu = 0
    if A[i] < A[i+1]:
        Mkabu = Mcashe // A[i]
        Mcashe = Mcashe % A[i] 

Mcashe += (Mkabu * A[-1])
print(Mcashe)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
m = A[0]
c = 1000
for i, a in enumerate(A):
  if i == N-1:
    if a != m:
      c += c // m * (a - m)
    continue
  
  if a <= A[i+1]:
    continue
  
  c += c // m * (a - m)
  m = A[i+1]
print(c)

Submission status: Accepted

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

def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    N = int(input())
    A = list(map(int, input().split()))

    return N, A

def main(N: int, A: list) -> None:
    """
    メイン処理.

    Args:\n
        N (int): 日数（2 <= N <= 80）
        A (list): i日目の株価（100 <= A_i <= 200）
    """
    # 求解処理
    pos = 1000
    for i in range(N - 1):
        stock = 0
        if A[i] < A[i + 1]:
            stock = pos // A[i]
        pos += (A[i + 1] - A[i]) * stock

    # 結果出力
    print(pos)

if __name__ == "__main__":
    # 標準入力を取得
    N, A = get_input()

    # メイン処理
    main(N, A)

Submission status: Accepted

Solution code:
 
# from math import factorial as fac
from collections import defaultdict
# from copy import deepcopy
import sys, math
f = None
try:
	f = open('q1.input', 'r')
except IOError:
	f = sys.stdin
if 'xrange' in dir(__builtins__):
	range = xrange
# print(f.readline())
# sys.setrecursionlimit(10**6)

	
def print_case_iterable(case_num, iterable):
	print("Case #{}: {}".format(case_num," ".join(map(str,iterable))))

def print_case_number(case_num, iterable):
	print("Case #{}: {}".format(case_num,iterable))

def print_iterable(A):
	print (' '.join(A))

def read_int():
	return int(f.readline().strip())
def read_int_array():
	return [int(x) for x in f.readline().strip().split(" ")]
def rns():
	a =  [x for x in f.readline().split(" ")]
	return int(a[0]), a[1].strip()
def read_string():
	return list(f.readline().strip())
def ri():
	return int(f.readline().strip())
def ria():
	return [int(x) for x in f.readline().strip().split(" ")]
def rns():
	a =  [x for x in f.readline().split(" ")]
	return int(a[0]), a[1].strip()
def rs():
	return list(f.readline().strip())
def bi(x):
	return bin(x)[2:]





from collections import deque
import math
NUMBER = 10**9 + 7
# NUMBER = 998244353
def factorial(n) : 
	M = NUMBER
	f = 1
  
	for i in range(1, n + 1):  
		f = (f * i) % M # Now f never can  
						# exceed 10^9+7  
	return f
def mult(a,b):
	return (a * b) % NUMBER

def minus(a , b):
	return (a - b) % NUMBER

def plus(a , b):
	return (a + b) % NUMBER

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		g, y, x = egcd(b % a, a)
		return (g, x - (b // a) * y, y)

def modinv(a):
	m = NUMBER
	g, x, y = egcd(a, m)
	if g != 1:
		raise Exception('modular inverse does not exist')
	else:
		return x % m
def choose(n,k):
	if n < k:
		assert false
	return  mult(factorial(n), modinv(mult(factorial(k),factorial(n-k)))) % NUMBER
from collections import deque, defaultdict 
import heapq


from types import GeneratorType
def bootstrap(f, stack=[]):
	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to

	return wrappedfunc


def dfs(g, timeIn, timeOut,depths,parents): 
	# assign In-time to node u 
	cnt = 0
	# node, neig_i, parent, depth
	stack = [[1,0,0,0]]
	while stack:
		v,neig_i,parent,depth = stack[-1]
		parents[v] = parent
		depths[v] = depth
		# print (v)
		if neig_i == 0:
			timeIn[v] = cnt    
			cnt+=1
		while neig_i < len(g[v]):
			u = g[v][neig_i]
			if u == parent:
				neig_i+=1
				continue
			stack[-1][1] = neig_i + 1
			stack.append([u,0,v,depth+1])
			break
		if neig_i == len(g[v]):
			stack.pop()
			timeOut[v] = cnt
			cnt += 1
  
# def isAncestor(u: int, v: int, timeIn: list, timeOut: list) -> str: 
# 	return timeIn[u] <= timeIn[v] and timeOut[v] <= timeOut[u] 

cnt = 0
@bootstrap
def dfs(v,adj,timeIn, timeOut,depths,parents,parent=0,depth=0):
	global cnt
	parents[v] = parent
	depths[v] = depth
	timeIn[v] = cnt
	cnt+=1
	for u in adj[v]:
		if u == parent:
			continue
		yield dfs(u,adj,timeIn,timeOut,depths,parents,v,depth+1)
	timeOut[v] = cnt
	cnt+=1
	yield 

def gcd(a,b): 
	if a == 0: 
		return b 
	return gcd(b % a, a) 
  
# Function to return LCM of two numbers 
def lcm(a,b): 
	return (a*b) / gcd(a,b) 
def get_num_2_5(n):
	twos = 0
	fives = 0
	while n>0 and n%2 == 0:
		n//=2
		twos+=1
	while n>0 and n%5 == 0:
		n//=5
		fives+=1
	return (twos,fives)
def shift(a,i,num):
	for _ in range(num):
		a[i],a[i+1],a[i+2] = a[i+2],a[i],a[i+1]

def equal(x,y):
	return abs(x-y) <= 1e-9
# def leq(x,y):
# 	return x-y <= 1e-9
def getAngle(a, b, c):
	ang = math.degrees(math.atan2(c[1]-b[1], c[0]-b[0]) - math.atan2(a[1]-b[1], a[0]-b[0]))
	return ang + 360 if ang < 0 else ang
def getLength(a,b):
	return math.sqrt((a[0]-b[0])**2 + (a[1]-b[1])**2)


from heapq import heapify, heappush, heappop

def bfs(adj):
	s = set()
	d = defaultdict(set)
	# print('\n'.join(map(str,E.items())))
	q = deque([])
	s.add(0)
	d[0].add(0)
	q.append((0,0))
	while len(q) > 0:
		v,depth = q.popleft()
		for u in adj[v]:
			if u not in s:
				s.add(u)
				d[depth+1].add(u)
				q.append((u,depth+1))
		# print(q)
	return d



def isSubsetSum(arr, n, summ): 
	  
	# The value of subarr[i][j] will be  
	# true if there is a 
	# subarr of arr[0..j-1] with summ equal to i 
	subarr =([[False for i in range(summ + 1)]  
			for i in range(n + 1)]) 
	  
	# If summ is 0, then answer is true  
	for i in range(n + 1): 
		subarr[i][0] = True
		  
	# If summ is not 0 and arr is empty,  
	# then answer is false  
	for i in range(1, summ + 1): 
		 subarr[0][i]= False
			  
	# Fill the subarr table in botton up manner 
	for i in range(1, n + 1): 
		for j in range(1, summ + 1): 
			if j<arr[i-1]: 
				subarr[i][j] = subarr[i-1][j] 
			if j>= arr[i-1]: 
				subarr[i][j] = (subarr[i-1][j] or 
								subarr[i - 1][j-arr[i-1]]) 
	  
	# uncomment this code to print table  
	# for i in range(n + 1): 
	# for j in range(summ + 1): 
	# print (subset[i][j], end =" ") 
	# print() 
	return subarr[n][summ] 

@bootstrap
def dfs(v,adj,vis,black):
	vis[v] = 1
	for u in adj[v]:
		if vis[u]==2:
			continue
		if vis[u] == 1:
			black.add((v,u)) 
			continue
		yield dfs(u,adj,vis,black)
	vis[v] = 2
	yield


def solution(a,n):
	yen = 1000
	stock = 0
	mx = 0
	for i in range(n-1):
		if a[i] < a[i+1] and yen:
			stock += yen // a[i]
			yen = yen % a[i]
		elif a[i] > a[i+1] and stock:
			yen += stock * a[i]
			stock = 0

	if stock > 0:
		yen += stock*a[n-1]
	return yen
def main():
	T = 1
	# T = ri()
	for i in range(T):
		n = ri()
		# n,m = ria()
		a = ria()
		# s = rs()
		# b = rs()
		# n,k,l	= ria()
		# a = ria()
		# adj = [list() for _ in range(n)]
		# for _ in range(m):
		# 	a,b=ria();
		# 	a-=1; b-=1
		# 	adj[a].append(b)

		x = solution(a,n)

		# continue
		if 'xrange' not in dir(__builtins__):
			print(x) # print("Case #"+str(i+1)+':',x)
		else:
			print >>output,str(x)
	if 'xrange' in dir(__builtins__):
		print(output.getvalue())
		output.close()

if 'xrange' in dir(__builtins__):
	import cStringIO
	output = cStringIO.StringIO()
#example usage:
#    for l in res:
#       print >>output, str(len(l)) + ' ' +  ' '.join(l)

if __name__ == '__main__':
	main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
money=1000
i=0
while i<N-1:
    k=1
    while A[i]==A[i+k]:
        if i+k==N-1:
            i=i+k
            break
        else:
            k+=1
    if i==N-1:
        break
    if A[i+k]>A[i]:
        kabu=money//A[i]
        money-=kabu*A[i]
        money+=kabu*A[i+k]
        i=i+k
    elif A[i+k]<A[i]:
        i=i+k

print(money)

Submission status: Accepted

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

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 ;count = 0 ;pro = 1

read = sys.stdin.buffer.read

n, *A = map(int, read().split())

now = 1000
for i in range(n-1):
    if A[i+1] > A[i]:
        now += (A[i+1] - A[i])*(now // A[i])
print(now)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N_all = int(readline())
A_all = list(map(int,readline().split()))
A = [A_all[0]]
for i in range(1,N_all):
    if A[-1] != A_all[i]:
        A.append(A_all[i])
N = len(A) 
if N == 1:
    print(1000)
    sys.exit()
money = 1000
kabu = 0 
for i in range(N):
    if i == 0:
        if A[i] > A[i+1]:
            continue
        else:
        	kabu = money // A[i]
        	money -= kabu * A[i]
    elif i == N-1:
        money += A[i]*kabu
        kabu = 0
    else:
        if A[i-1] < A[i] and A[i] > A[i+1]:
            money += A[i]*kabu
            kabu = 0
        if A[i-1] > A[i] and 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()))
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:
n=int(input())
a=[int(j) for j in input().split()]
l=a[:2]
if a[0]<=a[1]:b=True
else:b=False
for i,j in zip(a,a[1:]):
    if i<j:
        if b:
            l[-1]=j
        else:
            l.append(j)
            b=True
    elif i>j:
        if b:
            l.append(j)
            b=False
        else:
            l[-1]=j
ans=1000
for i,j in zip(l,l[1:]):
    if i<j:
        ans=(ans//i)*j+ans%i
print(ans)

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]:
        money = (money // a[i-1]) * a[i] + money % a[i-1]
    else:
        pass

print(money)

Submission status: Accepted

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

# state_of_up_or_down = False
money = 1000
# min_price = a[0]
# max_price = a[0]
for i in range(1, n):
    if a[i] > a[i - 1]:
        # max_price = a[i]
        # state_of_up_or_down = True
        money = (money // a[i-1]) * a[i] + money % a[i-1]
    # elif a[i] == a[i - 1]:
    #     if i == n - 1:
    #         money = (money // min_price) * max_price + money % min_price        
    #     pass
    else:
        pass
    #     if state_of_up_or_down:
    #         money = (money // min_price) * max_price + money % min_price
    #         state_of_up_or_down = False
    #     min_price = a[i]
    # print(money, min_price, state_of_up_or_down)
print(money)

Submission status: Accepted

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

state_of_up_or_down = False
money = 1000
min_price = a[0]
max_price = a[0]
for i in range(1, n):
    if a[i] > a[i - 1]:
        # min_price = min(a[i - 1], min_price)
        max_price = a[i]
        state_of_up_or_down = True
        if i == n - 1:
            money = (money // min_price) * max_price + money % min_price
    elif a[i] == a[i - 1]:
        if i == n - 1:
            money = (money // min_price) * max_price + money % min_price        
        pass
    else:
        if state_of_up_or_down:
            money = (money // min_price) * max_price + money % min_price
            state_of_up_or_down = False
        # max_price = a[i]
        min_price = a[i]
    # print(money, min_price, state_of_up_or_down)
print(money)

Submission status: Accepted

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

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

Submission status: Accepted

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

dp=[[0]*2 for i in range(n)]
dk=[[0]*2 for i in range(n)]

#--------------- kabu=0
dp[0][0]=1000
dk[0][0]=0
#--------------- all kabu
dp[0][1]=1000%a[0]
dk[0][1]=1000//a[0]

for k in range(1,n):
    dp[k][0]=max(dp[k-1][0],dp[k-1][1]+dk[k-1][1]*a[k])
    dk[k][0]=0

    dpk1=dp[k-1][0]%a[k]
    dkk1=dp[k-1][0]//a[k]
    v1=dk[k-1][1]*a[k]+dp[k-1][1]
    v2=dkk1*a[k]+dpk1
#    if dkk1>dk[k-1][1]:
    if v2>v1:
        dk[k][1]=dkk1
        dp[k][1]=dpk1
    else:
        dp[k][1]=dp[k-1][1]
        dk[k][1]=dk[k-1][1]

print(dp[n-1][0])

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
curr=1000
st=0
i=0
while i<n-1:
    if(l[i]<l[i+1]):
        st=curr//l[i]
        curr=curr-st*l[i]
        j=i
        while j<n-1 and l[j+1]>=l[j]:
            j+=1
        curr+=st*l[j]
        st=0
        i=j+1
    else:
        i+=1
print(curr)

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

dp = [0 for _ in range(N+1)]
dp[0] = 1000
for i in range(1, N):
    dp[i] = dp[i-1]
    for j in range(0, i):
        stock = dp[j] // A[j]
        money = dp[j] % A[j] + A[i] * stock
        # j日目に余ったお金とi日目に得たお金を足すとi日目に持っているお金になる
        dp[i] = max(dp[i], money)

print(dp[N-1])

Submission status: Accepted

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

stock = 0
rest  = 0
value = 1000

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

Submission status: Accepted

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

def short_long_decisions(xs):
    return [ *map(lambda t: t[0] <= t[1], zip(xs[:-1], xs[1:])), False ]

money   = 1000
stocks  = 0
actions = short_long_decisions(ai)

for i, action in enumerate(actions):
    if action:
        stocks += money // ai[i]
        money %= ai[i]

    else:
        money += stocks * ai[i]
        stocks = 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:
N = int(input())
A = list(map(int,input().split()))
m = 1000
k = 0

for i in range(N-1) :
    bk = m//A[i]
    bm = m - A[i] * bk
    am = bm + bk*A[i+1]
    ak = 0
    if m <= am :
        m = am
        k = ak
    else :
        pass

print(m)

Submission status: Accepted

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

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

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 = [0] + list(map(int, input().split()))

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

Submission status: Accepted

Solution code:
n = int(input())

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

B = []
for i in range(n-1):
    B.append(A[i+1]/A[i])

s = 1000
for i in range(n-1):
    if B[i] > 1.0:
        val = s // A[i]
        s = s - A[i] * val
        s = s + A[i+1] * val
print(s)

Submission status: Accepted

Solution code:
def solve():
  ans = 0
  N = int(input())
  A = [float('inf')]+list(map(int, input().split()))+[-float('inf')]
  UD = [0]*(N+1)
  for i in range(N+1):
    if A[i]>A[i+1]:
      UD[i] = -1
    elif A[i]<A[i+1]:
      UD[i] = 1
    else:
      UD[i] = UD[i-1]
  UD2 = [0]*N
  for i in range(N):
    if UD[i]>UD[i+1]:
      UD2[i] = -1
    elif UD[i]<UD[i+1]:
      UD2[i] = 1
  stock = 0
  money = 1000
  if -1 not in UD2:
    ind = -1
  else:
    ind = (N-1)-UD2[::-1].index(-1)
  for i in range(N):
    if UD2[i]==-1:
      money += A[i+1]*stock
      stock = 0
      if i==ind:
        break
    elif UD2[i]==1:
      stock,money = divmod(money,A[i+1])
  return money
print(solve())

Submission status: Accepted

Solution code:
n = int(input())
A = [*map(int, input().split())] + [0]
yen = 1000
kabu_yen = kabu_n = 0
for i in range(n):
    if A[i] < A[i+1]: # buy
        m = yen // A[i]
        cost = m * A[i]
        yen -= cost
        kabu_yen += cost
        kabu_n += m
    elif A[i] > A[i+1]: # sell
        yen += kabu_n * A[i]
        kabu_yen = kabu_n = 0
print(yen)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import copy
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


def solve():
    N = Scanner.int()
    A = Scanner.map_int()
    dp = [0 for _ in range(N + 1)]
    dp[0] = 1000
    for i in range(N):
        dp[i + 1] = max(dp[i], dp[i - 1])
        for j in range(0, i):
            a = dp[j] // A[j] * A[i] + dp[j] % A[j]
            dp[i + 1] = max(dp[i + 1], a)
    print(dp[N])


def main():
    # sys.setrecursionlimit(1000000)
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# D - Road to Millionaire
def main():
    N, *A = map(int, open(0).read().split())
    money, left, right = 1000, 0, 0
    while right < N:
        if A[right] > A[left]:
            stock, money = divmod(money, A[left])
            money += A[right] * stock
        left = right
        right += 1
    print(money)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def resolve():
    n = int(input())
    A = list(map(int, input().split()))
    account = 1000
    stock = 0

    inc_list = [1 if (A[i] < A[i+1]) else 0 for i in range(n-1)]
    for i in range(n):
        if(i < n-1 and inc_list[i] == 1):
            if(stock == 0):
                stock = int(account / A[i])
                account %= A[i]
        else:
            if(stock != 0):
                account += stock * A[i]
                stock = 0
    print(account)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
n = int(input())
A = [*map(int, input().split())] + [0]
yen = 1000
kabu_yen = kabu_n = 0
for i in range(1,n+1):
    if A[i-1] < A[i]: # buy
        m = yen // A[i-1]
        cost = m * A[i-1]
        yen -= cost
        kabu_yen += cost
        kabu_n += m
    elif A[i-1] > A[i]: # sell
        yen += kabu_n * A[i-1]
        kabu_yen = kabu_n = 0
print(yen)

Submission status: Accepted

Solution code:
n = int(input())
A = [*map(int, input().split())] + [0]
yen = 1000
kabu_yen = kabu_n = 0
for i in range(1,n+1):
    if A[i-1] < A[i]: # buy
        m = yen // A[i-1]
        cost = m * A[i-1]
        yen -= cost
        kabu_yen += cost
        kabu_n += m
    elif A[i-1] > A[i]: # sell
        yen += A[i-1] * kabu_n
        kabu_yen = 0
        kabu_n = 0
print(yen)

Submission status: Accepted

Solution code:
n, *a = map(int, open(0).read().split())
m = 1000
for a, b in zip(a, a[1:]):
  if a < b:m = m // a * b + m % a
print(m)

Submission status: Accepted

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