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:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 25 20:54:45 2020

@author: naoki
"""


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 = stock + money//A[i]
        money = money%A[i]
    else:
        money = money + stock*A[i]
        stock = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
M = 1000
min_ai = A[0]
max_ai = A[0]
for i in range(1, N):
    ai = A[i]
    if max_ai > ai:
        M = M % min_ai + (M // min_ai) * max_ai
        min_ai = ai
        max_ai = ai
    else:
        max_ai = ai

M = M % min_ai + (M // min_ai) * max_ai
print(M)

Submission status: Accepted

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

A = [A[0]] + [b for a,b in zip(A,A[1:]) if a != b]

if len(A) < 2:
    print(1000)
    exit()

diff = [a-b for a,b in zip(A[1:],A)]
B = [A[0]] if diff[0] > 0 else []

for i,(d1,d2) in enumerate(zip(diff, diff[1:]),start=1):
    if d1*d2 < 0:
        B.append(A[i])
B.append(A[-1])
t = iter(B)
c = 1000
for a,b in zip(t,t):
    c = c//a*b + c%a

print(c)

Submission status: Accepted

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

base = A[0]
up = False
down = False
kouho = [base]
for i in range(1, n):
    if A[i] - A[i - 1] > 0:
        up = True
        if down:
            kouho.append(A[i - 1])
            down = False
    elif A[i] - A[i - 1] < 0:
        down = True
        if up:
            kouho.append(A[i - 1])
            up = False
kouho.append(A[-1])
if A[1] < A[0]:
    kouho = kouho[1:]

ans = 1000
num = len(kouho)
money = 1000
stock = 0
for i in range(num):
    rate = kouho[i]
    if not stock:
        stock += money // rate
        money %= rate
    else:
        money += stock * rate
        stock = 0
        ans = max(ans, money)

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#import numpy as np
#import math
#from decimal import *
#from numba import njit

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

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

    print(amount)
main()

Submission status: Accepted

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

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

stocks = 0
money = 1000

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


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

Submission status: Accepted

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

p = [0 for _ in range(N)]

for i in range(1, N - 1):
    if A[i - 1] <= A[i] > A[i + 1]:
        p[i] = 1
    elif A[i - 1] >= A[i] < A[i + 1]:
        p[i] = 2

if A[0] > A[1]:
    p[0] = 1
if A[0] < A[1]:
    p[0] = 2
if A[-2] <= A[-1]:
    p[-1] = 1
if A[-2] > A[-1]:
    p[-1] = 2

res = 1000
kabu = 0

for i in range(N)[::-1]:
    if p[i] == 1:
        break
    if p[i] == 2:
        p[i] = 0

for i in range(N):
    if p[i] == 2:
        v = res // A[i]
        kabu += v
        res -= A[i] * v
    elif p[i] == 1:
        res += kabu * A[i]
        kabu = 0

print(res)

Submission status: Accepted

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

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

pre = 10**18
stock = 0
money = 1000
goup = False
for a in A:
    if a > pre:
        # buy in pre
        count = money//pre
        money -= count*pre
        stock += count
        goup = True
    else:
        if goup:
            money += stock*pre
            stock = 0
        goup = False
    pre = a

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

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int,input().split()))
k = 0
m = 1000
flag = 0
for i in range(1,n):
    if flag:
        if A[i]>=A[i-1]:
            continue
        else:
            m += k*A[i-1]
            k = 0
            flag = 0
    else:
        if A[i]<=A[i-1]:
            continue
        else:
            k,m = divmod(m,A[i-1])
            flag = 1
if flag:
    m += A[-1]*k
print(m)

Submission status: Accepted

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

kabu = 0
money = 1000

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

        else:
            money += A[i] * kabu
            kabu = 0

Submission status: Accepted

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

money = 1000
stock = 0

schedule = []
for i in range(n-1):
    if A[i] < A[i+1]:
        schedule.append(i)

for i in schedule:
    stock, money = divmod(money, A[i])
    money = money+stock*A[i+1]
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-1):
    if A[i+1] > A[i]:
        kabu += money // A[i]
        money %= A[i]
    else:
        money += kabu * A[i]
        kabu = 0
money += kabu * A[-1]
kabu = 0
print(money)

Submission status: Accepted

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

Submission status: Accepted

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

money = 1000
kabu = 0

a = []

for kabuka in given_a:
    if len(a) > 0 and a[-1] == kabuka:
        continue
    else:
        a.append(kabuka)

n = len(a)

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

print(money)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys,bisect,string,math,time,functools,random,fractions
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
rep=range;R=range
def Golf():n,*t=map(int,open(0).read().split())
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def MI():return map(int,input().split())
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def RA():return map(int,open(0).read().split())
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1):
    #h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in R(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def accum(ls):
    rt=[0]
    for i in ls:rt+=[rt[-1]+i]
    return rt
def bit_combination(n,base=2):
    rt=[]
    for tb in R(base**n):s=[tb//(base**bt)%base for bt in R(n)];rt+=[s]
    return rt
def gcd(x,y):
    if y==0:return x
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y
def YN(x):print(['NO','YES'][x])
def Yn(x):print(['No','Yes'][x])
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

mo=10**9+7
inf=float('inf')
FourNb=[(-1,0),(1,0),(0,1),(0,-1)];EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('WENS',FourNb));cursol=dict(zip('LRUD',FourNb))
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
read=sys.stdin.buffer.read;readline=sys.stdin.buffer.readline;input=lambda:sys.stdin.readline().rstrip()

########################################################################################################################################################################

show_flg=False
show_flg=True

ans=0


n=I()
a=LI()
p=a[0]

x=1000
t=0
s=0
for i in range(n):
    if p<a[i]:
        s=x//p
        #t+=s
        x+=s*(a[i]-p)
    #show(x,s,a[i],p)
    p=a[i]
    
print(x)

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]:
        q, r = divmod(money, A[i])
        money = r + q * A[i + 1]
print(money)

Submission status: Accepted

Solution code:
N = int(input())
#S = str(input())
#N, K= map(int, input().split())
A = list(map(int, input().split()))

money = 1000
book = 0
for i in range(1, N):
  if A[i] > A[i - 1]:
    book2 = int(money / A[i - 1])
    book += book2
    money -= book2 * A[i - 1]
  elif A[i] < A[i - 1]:
    money += book * A[i - 1]
    book = 0
  #print(i, money, book)  

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

Submission status: Accepted

Solution code:
n = raw_input()
q = 1000
ais = map(int, raw_input().split())

for u,v in zip(ais,ais[1:]):
	if v > u:
		s = q / u
		q %= u
		q += s * v
print q

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(1000000)

import bisect
import math
import collections
import heapq


def solve(N, As):
    diffs = [As[i] - As[i - 1] for i in range(1, N)]
    own = 0
    money = 1000
    for i in range(N - 1):
        if own == 0 and diffs[i] > 0:
            k = (money // As[i])
            own = k
            money -= k * As[i]
        elif own > 0 and diffs[i] < 0:
            money += own * As[i]
            own = 0

    if own > 0:
        money += own * As[-1]
    return money



if __name__ == "__main__":
    N = int(input())
    As = list(map(int, input().split(" ")))
    print(solve(N, As))

Submission status: Accepted

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

# 前からその時の最大を更新していく

dp[0] = 1000
dp[1] = 1000
for start in range(1, n):
    for end in range(start+1, n+1):
        if a[end] - a[start] > 0:
            cnt = dp[start] // a[start]
            money = dp[start] + (a[end] - a[start]) * cnt
            dp[end] = max(dp[end], money)
        else:
            dp[end] = max(dp[end], dp[start])
print(dp[-1])

Submission status: Accepted

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

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

if kabu:
    money += max(tmp, A[-1]) * kabu

print(money)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
import sys
import math
from collections import deque
from heapq import heappush, heappop

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


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


def isRaw():
    return list(map(int, ssRaw()))


INF = 1 << 29

DIV = (10**9) + 7
#DIV = 998244353

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac = fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV

    return CONV()


def cumsum(As):
    s = 0
    for a in As:
        s += a
        yield s


sys.setrecursionlimit(200005)


def dijkstra(G,start=0):
    heap = []
    cost = [INF]*len(G)
    heappush(heap,(0,start))
    while len(heap)!=0:
        c,n = heappop(heap)
        if cost[n] !=INF:
            continue
        cost[n]=c
        for e in G[n]:
            ec,v = e
            if cost[v]!=INF:
                continue
            heappush(heap,(ec+c,v))
    return cost


def main():
    N = iRaw()
    As = isRaw()
    isUP=[False]*N
    lastDifVal=As[-1]
    for n in range(N-1,0,-1):
        #print(n)
        if As[n]!=As[n-1]:
            lastDifVal=As[n]
            isUP[n-1] = lastDifVal>As[n-1]
    money = 1000
    stock = 0
    for n in range(N):
        a = As[n]
        if isUP[n]:
            stock += money//a
            money = money%a
        else:
            money +=stock*a
            stock=0
    
    print(money+stock*As[-1])

main()

Submission status: Accepted

Solution code:
import heapq
t = 1
def max(a,b):
	if a > b:
		return a
	return b
while t > 0:
	t -= 1
	# n = map(int,input().split())
	n = int(input())
	v = list(map(int,input().strip().split()))[0:n]
	m = 1000
	i = 0
	while i < n:
		j = i
		# print(i)
		while j+1 < n and v[j+1] >= v[j]:
			j += 1
		x = m//v[i]
		m = m%v[i]
		temp = x*v[j]
		m += temp
		# print(m,i)
		i = j+1
		# m -= x*a[i]
	print(m)
			# for i in range(q):
	# 	p = int(input().strip())
	# 	v.append(p)
	# for i in range(n):
	# 	l.append(0)
	# for i in v:
	# 	l[i-1] += 1
	# for i in range(n):
	# 	if(l[i] <= q-k):
	# 		print("No")
	# 	else:
	# 		print("Yes")

Submission status: Accepted

Solution code:
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import lru_cache, reduce
from math import gcd
from operator import add, itemgetter, mul, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N = int(sys.stdin.buffer.readline())
A = list(map(int, sys.stdin.buffer.readline().split()))

dp = [1000] * (N + 1)
# 全部買うか全部うるか
for i in range(N):
    dp[i + 1] = dp[i]
    for j in range(i):
        dp[i + 1] = max(dp[i + 1], dp[j] // A[j] * A[i] + dp[j] % A[j])
print(dp[-1])
# print(dp)

Submission status: Accepted

Solution code:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

now=1000
kabu=0
for i in range(n):
    ud=-1
    for j in range(i+1,n):
        if a[i]<a[j]:
            ud=1
            break
        elif a[i]>a[j]:
            ud=0
            break
    if ud==1:
        kabu+=now//a[i]
        now-=now//a[i]*a[i]
    elif ud==0:
        now+=kabu*a[i]
        kabu=0
    # print(now,kabu,ud)
print(now+kabu*a[-1])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n = ri()
    la = rli()
    m = 1000
    s = 0
    ans = 1000
    for i in range(n-1):
        if s > 0:
            if la[i] <= la[i+1]:
                continue
            m += s*la[i]
            s = 0
        else:
            if la[i] >= la[i+1]:
                continue
            s = m//la[i]
            m -= s*la[i]
        ans = max(ans, m+s*la[i])
    ans = max(ans, m+s*la[n-1])
    print(ans)
        



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from operator import itemgetter

sys.setrecursionlimit(10**9)
input = sys.stdin.readline

def ii(): return int(input())
def mi(): return map(int, input().split())
def lmi(): return list(map(int, input().split()))
def iif(n): return [int(input()) for _ in range(n)]
def lmif(n): return [list(map(int, input().split())) for _ in range(n)]
def ss(): return input().split()

def main():
    mod = 1000000007
    
    n = ii()
    A = lmi()

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

    print(m)

    return

main()

Submission status: Accepted

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

B=[]
T=[]
if A[0]<A[1]:
    st=ans//A[0]
    ans%=A[0]
for i in range(1,N-1):
    if A[i-1]<=A[i] and A[i]>=A[i+1]: #極大
        ans+=A[i]*st
        st=0
    
    elif A[i-1]>=A[i] and A[i]<=A[i+1]: #極小
        st+=ans//A[i]
        ans%=A[i]
#    print(i,ans,st)

if st>0:
    ans+=st*A[-1]
print(ans)

Submission status: Accepted

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

        cur=a[i]
print(money)

Submission status: Accepted

Solution code:
def buy(my_money, A, count):
    return my_money%A, count + my_money//A

def sell(my_money, A, count):
    return my_money + A*count, 0

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

now = 1000  # 所持金
kabu = 0

for i in range(N-1):
    if A[i] < A[i+1]:
        now, kabu = buy(now, A[i], kabu)
    else:
        now, kabu = sell(now, A[i], kabu)

now, kabu = sell(now, A[N-1], kabu)

print(now)

Submission status: Accepted

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

buy=[]
i=0
while(i<=n-2):
    if A[i]<A[i+1]: #株が値上がったとき
        buy.append(i)
    i=i+1
money=1000
stock=0
for i in buy:
    #株を買う
    count=money//A[i]
    money=money-count*A[i]
    stock=stock+count
    #株をうる
    rieki=stock*A[i+1]
    money=money+rieki
    stock=0
print(money)

Submission status: Accepted

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


now = 1000
kabu = 0
amari = 1000

for i, a in enumerate(A):
    now = max(kabu*a+amari, now)
    kabu = now//a
    amari = now-a*kabu

print(now)

Submission status: Accepted

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

L = []

for i in range(N - 1):
  if A[i] < A[i + 1]:
    L.append(i)
    s = i + 1
    break
else:
  print(1000)
  exit()

f = True
for i in range(s, N - 1):
  if f and A[i] > A[i + 1]:
    L.append(i)
    f = False
  elif not f and A[i] < A[i + 1]:
    L.append(i)
    f = True

ans = 1000
f = True
for i in L:
  if f:
    k = ans // A[i]
    ans -= A[i] * k
    f = False
  else:
    ans += k * A[i]
    f = True

if not f:
  ans += k * A[-1]

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int,input().split()))

B = [0] * n
m = 100
for i in range(n-1,-1,-1):
    if m < A[i]:
        B[i] = 1
    m = A[i]
# print(B)

ans = 1000
k = 0
for i in range(n):
    if (1 <= i < n-1 and A[i-1] <= A[i] and A[i] >= A[i+1]) or (i == n-1 and A[i-1] <= A[i]):
        ans += k * A[i]
        k = 0
    if (1 <= i < n-1 and A[i-1] >= A[i] and A[i] <= A[i+1]) or (i == 0 and A[i] <= A[i+1]):
        kau = ans // A[i]
        ans -= kau * A[i]
        k += kau
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]:
        money+=kabu*a[i]
        kabu=0
    elif a[i]<a[i+1]:
        money+=kabu*a[i]
        kabu=money//a[i]
        money=money%a[i]
    #print(money,kabu)

money+=kabu*a[n-1]

print(money)

Submission status: Accepted

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

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

    print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
yen = 1000
stock = 0
an = []
i = 0
while 1:
    while i <= n - 2 and a[i] >= a[i+1]:
        i += 1
    if i == n - 1:
        print(yen)
        exit()
    stock, yen = divmod(yen, a[i])
    while i <= n-2 and a[i] <= a[i+1]:
        i += 1
    stock, yen = 0, yen + a[i] * stock

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())
arr = list(map(int,input().split()))
c = 1000
ans = 0
for i in range(1, len(arr)):
    if arr[i] > arr[i-1]:
        st = c//arr[i-1]
        rem = c%arr[i-1]
        c = st*(arr[i]) + rem
print(c)

Submission status: Accepted

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

import sys
input=sys.stdin.readline

n=int(input())
arr=list(map(int,input().split()))
kane=1000
kabu=0
for i in range(n-1):
    if arr[i]>=arr[i+1]:
        continue
    else:
        kane=kane%arr[i]+(kane//arr[i])*arr[i+1]
print(kane)

Submission status: Accepted

Solution code:
def main():

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

    v = 1000
    i = 0

    while i < N:
        while i < N-1 and A[i+1] <= A[i]:
            i += 1
        buy = A[i]
        i += 1
        while i < N-1 and A[i+1] >= A[i]:
            i += 1
        if i < N:
            sell = A[i]
            v = (v // buy) * sell + (v - v//buy * buy)
            i += 1
    return v

if __name__ == '__main__':
    print(main())