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: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
start = 0
S = defaultdict(int)
U = defaultdict(int)
for i in range(n-1):
    if a[start] < a[i+1]:
        S[i] = 'kau'
        start = i+1
    elif a[start] >= a[i+1]:
        start = i+1

for i,s in S.items():
    goal = i+1
    while S[i] != 'kau':
        if a[goal] < a[i+1]:
            goal += 1
        i += 1
    U[goal] = 'uru'

fee = 1000
kabu = 0
for i in range(n):
    if S[i] == 'kau':
        b,c = divmod(fee,a[i])
        fee = c
        kabu += b
    if U[i] == 'uru':
        fee += kabu * a[i]
        kabu = 0
print(fee)

Submission status: Wrong Answer

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

money = 1000
stock = 0
leave_max = max(a)

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

    leave_max = max(a[i:])

    if a[i] >= a[i+1]:
        money += a[i] * stock
        stock = 0
        if a[i] >= leave_max:
            break
        else:
            continue

    elif a[i] < a[i+1]:
        stock = money // a[i]
        money -= stock * a[i]

print(money)

Submission status: Wrong Answer

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

ans = 1000
buy = A[0]
sell = 0
cnt = 0
flg = False
for i in range(1, N):
    if flg:
        buy = A[i]
        flg = False

    if buy < A[i] and sell < A[i]: #真に大きい時
        if cnt: #株を既に買っていたら
            sell = A[i]
        else:
            cnt = ans//buy #買う株は決まった
            sell = A[i] #売る時の株の値段
    else:
        if sell:
            ans += (sell - buy) * cnt
            flg = True #株を売った
            sell = 0
            cnt = 0
        else: #買う株をできるだけ安いのにしたい
            buy = A[i]

if sell: #最後に売る株が決まったらまだ売ってない
    ans += (sell - buy) * cnt
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
#import string
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def solve():
    n = int(stdin.readline().rstrip())
    A = list(map(int, stdin.readline().rstrip().split()))
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    #word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    money = 1000
    kabu = 0
    down = 0
    up = 0
    kijun = A[0]
    for i in range(1,n):
        a = A[i]
        if i == 1:
            if kijun < a:
                buy = kijun
                katta = money//buy
                kabu += katta
                money -= katta*buy
                down = 0
                up = 1
                kijun = a
            elif kijun > a:
                down = 1
                kijun = a
        if up == 1:
            if kijun > a:
                sell = kijun
                money += sell * kabu
                kabu = 0
                up = 0
                down = 1
                kijun = a
            else:
                kijun = a
        elif down == 1:
            if kijun < a:
                buy = kijun
                katta = money//buy
                kabu += katta
                money -= katta*buy
                down = 0
                up = 1
                kijun = a
            else:
                kijun = a
    if kabu > 0:
        money += kabu * A[-1]
    print(money)




if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
def function(N, A):
    money = 1000
    kabu = 0
    for i in range(N-1):
        if (i == 0) & (A[0] < A[1]):
            kabu = int(1000/A[0])
            money = 1000-kabu*A[0]
        elif (A[i-1] >= A[i]) & (A[i] < A[i+1]):
            kabu = int(money/A[i])
            money = money-kabu*A[i]
        elif (A[i-1] <= A[i]) & (A[i] > A[i+1]):
            money = money+kabu*A[i]
            kabu = 0
    print(money+kabu*A[N-1])


if __name__ == '__main__':
    N = int(input())
    A = input().split()
    A = [int(a) for a in A]
    function(N, A)

Submission status: Wrong Answer

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

s = 0
b = 1000

i = 0
while i < n:
	mn = arr[i]
	tmp = mn
	while i + 1 < n:
		if arr[i + 1] >= tmp:
			i += 1
			tmp = arr[i]
		else:
			s = b // mn
			b %= mn
			
			s *= tmp
			b += s
			i += 1
			break
	if i == n - 1:
		if tmp >= mn:
			s = b // mn
			b %= mn
			
			s *= tmp
			b += s
			i += 1
		break
print(b)

Submission status: Wrong Answer

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

C = 1000
S = 0

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

if S > 0:
    C += S*A[-1]

print(C)

Submission status: Wrong Answer

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 金がある→買う
        stock += wallet // A[i]
        wallet -= stock * 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: Wrong Answer

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

is_start_increase = [0]*N
is_end_increase = [0]*N
is_increasing = [0]*N

for i in range(1, N):
    if A[i-1] <= A[i]:
        is_increasing[i] = 1
        if i==1:
            is_increasing[i] = 1

for i in range(N-1):
    if i == 0 and is_increasing[i+1] == 1:
        is_start_increase[i] = 1
    if i == 1 and is_start_increase[i-1]==1:
        continue
    elif is_increasing[i] == 1 and is_increasing[i-1] == 0:
        is_start_increase[i] = 1
    elif is_increasing[i] == 1 and is_increasing[i+1] == 0:
        is_end_increase[i] = 1


money = 1000
stock = 0
for i in range(N):
    if i==N-1:
        # print("last", i)
        money += stock * A[i]
        break
    if is_start_increase[i]:
        # print("start", i)
        stock += money // A[i]
        money -= A[i] * stock
    if is_end_increase[i]:
        # print("end", i)
        money += stock * A[i]
        stock = 0

print(money, stock)
# dp = [[0, 0, 0, 0] for i in range(N+1)]
# dp[0][0] = 1000 # 何もしない
# dp[0][1] = 1000 # 買う
# dp[0][2] = 1000 # 売り
# dp[0][3] = 0 #株

# for i in range(1,N+1):
#     dp[i][2] = max(dp[i-1][0])
#     dp[i][0] = dp[i-1][0]
#     dp[i][3] = dp[i][3]
#     if (dp[i-1][0]//A[i]) >= (dp[i-1][2]//A[i]):
#         dp[i][3] = dp[i-1][0]//A[i]
#         dp[i][1] = dp[i-1][0] - A[i]*dp[i][3]
        
#     else:
#         dp[i][3] = dp[i-1][2]//A[i]
#         dp[i][1] = dp[i-1][2] - A[i]*dp[i][3]
        
    
#     # dp[i][1] = max(dp[i-1][0] - A[i] * (dp[i-1][0]//A[i]), dp[i-1][2] - A[i] * (dp[i-1][2]//A[i]))


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

Submission status: Wrong Answer

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

stock = 0
money = 1000
prev_trend = a[1] - a[0]

if prev_trend > 0:
    stock += money // a[0]
    money -= a[0] * (money // a[0])

if len(a) > 2:
    for i in range(1, n-1):
        next_trend = a[i+1] - a[i]
        if next_trend * prev_trend < 0:
            if prev_trend > 0:
                money += a[i] * stock
                stock = 0
            else:
                stock += money // a[i]
                money -= a[i] * (money // a[i])
            prev_trend = a[i+1] - a[i]

if prev_trend >= 0:
    money += a[n-1] * stock
    stock = 0

print(money)

Submission status: Wrong Answer

Solution code:
N = int(input())
*A, = map(int, input().split())
stack = [(1000, 0, 0, True)]
ans = 1000
while stack:
    money, stock, day, buy = stack.pop()
    if day >= N: ans = max(ans, money); continue
    if buy:
        while day < N - 1 and A[day] >= A[day + 1]:
            day += 1
        st, mon = divmod(money, A[day])
        stack.append((mon, st, day + 1, False))
    else:
        while day < N - 1 and A[day] <= A[day + 1]:
            day += 1
        st = 0; mon = money + A[day] * stock
        stack.append((mon, st, day + 1, True))
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
A = list(map(int,readline().split()))
money = 1000
num = 0 
pre_price = 0
for i in range(N):
    low_flag = False
    high_flag = False
    money += A[i]*num
    num = 0
    for j in range(i+1,N):
        if A[i] < A[j]:
            high_flag = True
        if A[i] > A[j]:
            low_flag = True
    if high_flag and low_flag == False:
        tmp_num = money // A[i]
        price = tmp_num * A[i]
        money -= price
        num += tmp_num
        pre_price = A[i]
print(money)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
money=1000
kabu=0
for i in range(n):
    if not max(a) == a[0]:
        newkabu = money//a[0]
        kabu += newkabu
        money -= a[0] * newkabu
    if not min(a) == a[0]:
        money += kabu*a[0]
        kabu=0
    if i == n-1:
        money += kabu*a[0]
    a.pop(0)
print(money)

Submission status: Wrong Answer

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

money = 1000
stock = 0

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

print(money)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
dp = [[-1 for _ in range(N+1)] for _ in range(100)]
dp[0][0] = 1000
for n in range(1,N):
    for i in range(100):
        # n日目
        for j in range(100):
        # n-1日目
            if dp[j][n-1] != -1:
                dp[i][n] = max(dp[j][n-1]+(j-i)*A[n-1],dp[i][n])
ans = 1000
for i in range(20):
    if dp[i][-2] != -1:
        if dp[i][-2]+i*A[-1] > ans:
            ans = dp[i][-2]+i*A[-1]
print(ans)

Submission status: Wrong Answer

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

ans = 1000
buy = A[0]
sell = 0
cnt = 0
flg = False
for i in range(1, N):
    if flg:
        buy = A[i]
        sell = 0
        cnt = 0
        flg = False

    if buy < A[i] and sell < A[i]: #真に大きい時
        if cnt: #株を既に買っていたら
            sell = A[i]
        else:
            cnt = ans//buy #買う株は決まった
            sell = A[i] #売る時の株の値段
    else:
        if sell:
            ans += (sell - buy) * cnt
            flg = True #株を売った
        else: #買う株をできるだけ安いのにしたい
            buy = A[i]

if sell and flg != True: #最後に売る株が決まったらまだ売ってない
    ans += (sell - buy) * cnt
print(ans)

Submission status: Wrong Answer

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

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

M = 0

while M == 0:
    if len(AS) == 1:
        M = 2
    elif AS[0] >= AS[1]:
        AS.pop(0)
    else:
        M = 1

BS = [AS[0]]
T = AS[0]
B = AS[0]

if M == 2:
    print(1000)
else:
    for i in range(1, len(AS)):
        if i < len(AS)-1:
            if AS[i] > T:
                T = AS[i]
            elif AS[i] < T:
                B = AS[i]
                BS.append(T)
                BS.append(B)
                T = AS[i]
        else:
            if AS[i] > T:
                BS.append(AS[i])
    money = 1000
    kabu = 0
    for i in range(len(BS)):
        if i % 2 == 0:
            kabu = money // BS[i]
            money = money - (kabu * BS[i])
        else:
            money = money + (kabu * BS[i])
            kabu = 0
    print(money)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)

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

l = []
s = 0
for i in range(N-1):
    if A[i] > A[i+1]:
        l.append([s,i])
        s = i+1
    else:
        continue

l.append([s,N-1])

ans = 1000
for s,e in l:
    kabu = (ans//A[s])
    ans += (A[e]-A[s])*kabu
    print(ans,kabu)

print(ans)

Submission status: Wrong Answer

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

kai=[]
uri=[]
sokone=A[0]
takane=A[0]
for i in range(1,N):
    if A[i-1]<=A[i]:
        takane=A[i]
        if i==(N-1) and takane>sokone:
            uri.append(takane)
            kai.append(sokone)
    else:
        if sokone<A[i]:
            uri.append(takane)
            kai.append(sokone)
            sokone=A[i]

kabu=0
money=1000
for i in range(len(kai)):
    #kabu+=money//kai[i]
    money=money%kai[i]+uri[i]*(money//kai[i])
  

print(money)

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    kai = A[0]
    uri = A[0]
    flag=0
    temoti = 1000
    for i in range(1,N-1):
        if kai < A[i] and uri<A[i]:
            uri=A[i]
            flag=1
        if flag==1:
            if uri>A[i]:
                temoti = temoti + temoti // kai *(uri-kai)
                kai = A[i]
                uri = A[i]
                flag=0

    if uri<A[N-1]:
        temoti = temoti + temoti // kai * (A[N-1]-kai)

    print(temoti)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
X = [A[0]]
for i in range(1, N):
  if A[i] != A[i-1]:
    X.append(A[i])
B, C = [], []
n = len(X)
if n==1:
  print(1000)
else:
  status = 0
  result = 1000
  now_m = 1000
  k = 0
  if X[0]>X[1]:
    B.append(0)
  else:
    C.append(0)
  for i in range(1, n-1):
    if X[i-1]<X[i] and X[i]>X[i+1]:
      B.append(i)
  for i in range(1, n-1):
    if X[i-1]>X[i] and X[i]<X[i+1]:
      C.append(i)
  if X[n-2]<X[n-1]:
    B.append(n-1)
  else:
    C.append(n-1)
  S = set(B+C)
  if 0 in B:
    S.remove(0)
  for s in S:
    if status==0:
        k = now_m//X[s]
        now_m -= k*X[s]
        status = 1
    else:
        now_m += k*X[s]
        result = max(result, now_m)
        k = 0
        status = 0
  print(result)

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import decimal
import itertools
from collections import deque
from functools import reduce
import heapq
import copy
n = int(input())
#n, k = map(int, sys.stdin.readline().split())
#s = input()
a = list(map(int, sys.stdin.readline().split()))

c = 1000
i = 0
while (i < n):
    ma = a[i]
    mi = a[i]
    mapo = i
    mipo = i
    j = 0
    while (i+j < n):
        if a[i+j] < mi:
            mi = a[i+j]
            mipo = i+j

        if a[i+j] > ma:
            ma = a[i+j]
            mapo = i+j
            break

        j += 1

    if mapo == i:
        break

    
    for k in range(i+j, n):
        if a[k] < a[i+j]:
            x = c // mi
            y = x * (ma - mi)
            c += y
            i += (j + 1)
            break

        if k == n-1:
            x = c // mi
            y = x * (max(a) - mi)
            c += y
            print(c)
            sys.exit()
    

print(c)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
money = 1000
cab = 0
lowprice = A[0]
value = []
check = True
for i in range(1,N):
    if(lowprice>A[i]):
        lowprice = A[i]
        check= True
    elif(lowprice<A[i] and check == True):
        high_price = A[i]
        cab=money//lowprice
        money-=(lowprice*cab)
        money+=(high_price*cab)
        cab = 0
        check = False
        lowprice = high_price
print(money)

Submission status: Wrong Answer

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

money = 1000
stack = 0
up = []
last_high = 0
high = 0
low = a[0]

for i in range(n):
    if i == 0:
        up.append(-1)
    elif a[i] > a[i - 1]:
        up.append(1)
    elif a[i] < a[i - 1]:
        up.append(-1)
    else:
        up.append(0)
print(up)

for i in range(n):
    if up[i] == 1:
        high = a[i]
        for j in range(last_high, i):
            if up[j] == -1:
                low = a[j]
        stack = money // low
        money %= low
        money += stack * high

print(money)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

d = defaultdict(lambda: 0)
d[0] = 1000

for i in range(N):
    dd = d.copy()
    for s,m in dd.items():
        if m%A[i] != 0:
            temp = m//A[i]
            for j in range(1,temp+1):
                if(d[s+j]<m-j*A[i]):
                    d[s+j]=m-j*A[i]
        else:
            d[s+m//A[i]]=0
        if d[0] < m+s*A[i]:
            d[0] = m+s*A[i]

print(d[0])

Submission status: Wrong Answer

Solution code:
MAX = 1000

n = int(input())
a = list(map(int, input().split()))
dp = [[-1 for j in range(MAX + 1)] for i in range(n)]
dp[0][0] = 1000
for k in range(1, MAX + 1):
    if 1000 - a[0] * k < 0:
        break
    dp[0][k] = 1000 - a[0] * k
# print(dp[0])
for i in range(1, n):
    for j in range(MAX + 1):
        dp[i][j] = max(dp[i][j], dp[i - 1][j])
        # 買うとき
        for k in range(1, MAX + 1):
            if j - k < 0:
                break
            if dp[i - 1][j - k] - a[i] * k < 0:
                break
            dp[i][j] = max(dp[i][j], dp[i - 1][j - k] - a[i] * k)
        # 売る時
        for k in range(1, MAX + 1):
            if j + k >= MAX + 1:
                break
            if dp[i - 1][j + k] < 0:
                break
            # if dp[i - 1][j + k] + a[i] * k < 0:
            #     break
            dp[i][j] = max(dp[i][j], dp[i - 1][j + k] + a[i] * k)
    # print(dp[i])
# print(dp)
ans = max(dp[-1])
print(max(ans, 0))

Submission status: Wrong Answer

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 = M - X * A[i]
    
    elif A[i] > A[i+1]:
        M = M + A[i] * X
        X = 0
    
if X > 0:
    M = M + X * A[N-1]

print(int(M))

Submission status: Wrong Answer

Solution code:
N=int(input())
A= list(map(int,input().split()))
kabu=0
kane=1000
kabukin=0
for a in range(N-1):
    if A[a]<A[a+1]:
        #if kabukin<A[a]*kabu:
            kabu=int(kane/A[a])
            kabukin=kabu*A[a]
            kane=kane-kabu*A[a]
    elif A[a]>A[a+1] and kabu>=1:
        kane=kane+kabu*A[a]
        kabu=0

if kabu>0:
    kane+=kabu*A[-1]
print(kane)

Submission status: Wrong Answer

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


def buy(kabuka, kabu, money):
    buy_num = money//kabuka
    money = money - buy_num * kabuka
    kabu = kabu + buy_num

    return kabu, money


def sell(kabuka, kabu, money):
    money = money + kabu * kabuka
    kabu = 0

    return kabu, money


kabu = 0
buy_price = 0
money = 1000
for i in range(N - 1):

    if (A[i] > max(A[i + 1:N])):  # 下降
        if (kabu > 0):
            kabu, money = sell(A[i], kabu, money)
        continue

    if (A[i] > buy_price):
        if (kabu > 0):
            kabu, money = sell(A[i], kabu, money)

    if (kabu == 0 and A[i] > min(A[i + 1:N])):
        continue

    kabu, money = buy(A[i], kabu, money)


money += kabu * A[N - 1]

print(money)

Submission status: Wrong Answer

Solution code:
def solve():
    n = int(input())
    a = list(map(int, input().split()))
    s = [0] * n
    for i in range(n - 1):
        if a[i + 1] > a[i]:
            s[i + 1] = 1
        elif a[i + 1] == a[i]:
            continue
        else:
            s[i + 1] = -1
    #print(s)
    tak = 1000
    stock = 0
    for i in range(n - 1):
        if s[i + 1] == 1 and not stock:
            stock = tak // a[i]
            tak = tak % a[i]
        elif s[i + 1] == -1 and stock:
            tak += stock * a[i]
            stock = 0
    if s[-1] == 1:
        tak += a[-1] * stock
    print(tak)

solve()

Submission status: Wrong Answer

Solution code:
N=int(input())
A= list(map(int,input().split()))
kabu=0
kane=1000
kabukin=0
for a in range(N-1):
    if A[a]<A[a+1]:
        #if kabukin<A[a]*kabu:
            kabu=int(kane/A[a])
            kabukin=kabu*A[a]
            kane=kane-kabu*A[a]
    elif A[a]>A[a+1] and kabu>=1:
        kane=kane+kabu*A[a]
        kabu=0
    print(kane,kabu)
if kabu>0:
    kane+=kabu*A[-1]
print(kane)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

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

money = 1000
stock = 0
status = "wait-for-buying"

last_sell = A.index(max(A))
for i in range(A.index(max(A))):
    if status == "wait-for-buying":
        if A[i] > A [i+1]:
            pass
        else:
            #buy
            stock = money//A[i]
            money = money%A[i]
            status = "wait-for-selling"
            
    else:
        if A[i] < A [i+1]:
            pass
        else:
            #sell
            money = stock*A[i]
            stock = 0
            status = "wait-for-buying"

money += stock*max(A)
print(money)

Submission status: Wrong Answer

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

def main():
    N = int(input())
    A = list(map(int, input().split()))
    cnt = 0
    money = 1000
    for i in range(N - 1):
        if A[i] < A[i + 1]:
            cnt = money // A[i]
            money -= cnt * A[i]
        elif A[i] > A[i + 1]:
            if cnt > 0:
                money += cnt * A[i]
                cnt = 0
    if cnt > 0:
        money += cnt * A[N-1]
        cnt = 0
    print(money)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
MAX = 100

n = int(input())
a = list(map(int, input().split()))
dp = [[-1 for j in range(MAX + 1)] for i in range(n)]
dp[0][0] = 1000
for k in range(1, MAX + 1):
    if 1000 - a[0] * k < 0:
        break
    dp[0][k] = 1000 - a[0] * k
# print(dp[0])
for i in range(1, n):
    for j in range(MAX + 1):
        dp[i][j] = max(dp[i][j], dp[i - 1][j])
        # 買うとき
        for k in range(1, MAX + 1):
            if j - k < 0:
                break
            if dp[i - 1][j - k] - a[i] * k < 0:
                break
            dp[i][j] = max(dp[i][j], dp[i - 1][j - k] - a[i] * k)
        # 売る時
        for k in range(1, MAX + 1):
            if j + k >= MAX + 1:
                break
            if dp[i - 1][j + k] < 0:
                break
            # if dp[i - 1][j + k] + a[i] * k < 0:
            #     break
            dp[i][j] = max(dp[i][j], dp[i - 1][j + k] + a[i] * k)
    # print(dp[i])
# print(dp)
ans = max(dp[-1])
print(ans)

Submission status: Wrong Answer

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

al = list(dict.fromkeys(al))
n = len(al)
ans = 0
for v in itertools.product(range(3),repeat=n):
    money = 1000
    kabu = 0

    for i in range(n):
        if v[i] == 0:
            kabu += money // al[i]
            money = money % al[i]
        elif v[i] == 1:
            money += kabu * al[i]
            kabu = 0
        else:
            continue
    ans = max(ans, money)
print(ans)

Submission status: Wrong Answer

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

# 頂点を集める
now = a_list[0]
desc = True if a_list[0] > a_list[1] else False
i = 1
kabu = 0
money = 1000
if not desc:
  kabu = money // now
  money -= now * kabu
while i < len(a_list)-1:
  if desc:
    if now >= a_list[i+1]:
      now = a_list[i+1]
    else:
      # 次上がるなら株買う
      kabu = money // now
      money -= now * kabu
      desc = False
  else:
    if now <= a_list[i+1]:
      now = a_list[i+1]
    else:
      # 次下がるなら売る
      money += kabu * now
      kabu = 0
      desc = True
  now = a_list[i+1]
  i+=1

money += kabu * a_list[-1]
print(max(1000,money))

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right

def main():
    N = int(input())
    A = list(map(int, input().split()))
    INF = 10 ** 18
    last_max = A[0]
    last_min = A[0]

    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]

            nx_bought_idx = bisect_right(bought_point,i)
            bought_value = A[nx_bought_idx]
            j = i - 1
            while j >= 0 and money >= 100:
                if A[j] < bought_value and money < A[i]:
                    money -= A[j]
                    stock += 1
                    break
                j -= 1
        
        if i in bought_point:
            bought = stock
            stock = 0
            money += bought * A[i]
    print(money)
    


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
K = [0]*N
s = 1000
kab = 0

if A[0] < A[1]:
  K[0] = -1
elif A[0] > A[1]:
  K[0] = 1
for i in range(1, N):
  if A[i-1] < A[i]:
    K[i] = 1 # 1は最高値
    if K[i-1] == 1: 
      K[i-1] == 0
  elif A[i-1] > A[i]:
    K[i] = -1 # -1は最低値
    if K[i-1] == -1:
      K[i-1] == 0
#print(K)
M = list(K)
for i in range(1, N):
  #print(-i, K[-i])
  if K[-i] == 1:
    break
  elif (K[-i] == -1):
    K[-i] = 0

#print(K)
  
for i in range(N):
  if K[i] == -1:
    kab = s // A[i]
    s -= A[i]*kab
  elif K[i] == 1:
    s += A[i]*kab
    kab = 0
print(s)

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    kai = A[0]
    uri = A[0]
    flag=0
    temoti = 1000
    for i in range(1,N-1):
        if kai < A[i] and uri<A[i]:
            uri=A[i]
            flag=1
        if flag==1:
            if uri>A[i]:
                temoti = temoti + temoti / kai *(uri-kai)
                kai = A[i]
                uri = A[i]
                flag=0

    if uri<A[N-1]:
        temoti = temoti + temoti // kai * (A[N-1]-kai)

    print(temoti)

Submission status: Wrong Answer

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())
    d = deque(A)
    d.appendleft(200)
    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)

    if len(il) == 1:
        print(1000)
    else:
        b = 1000
        s = 0
        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)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

delta_a = [0] * (n-1)
for i in range(n-1):
  delta_a[i] = a[i+1] - a[i]

stock = 0
money = 1000
for i in range(n-1):
  if delta_a[i] > 0 and (delta_a[i-1] < 0 or i == 0):
    stock = money // a[i]
    money = money % a[i]
  elif delta_a[i] < 0 and delta_a[i-1] >= 0  and stock != 0:
    money += stock * a[i]
    stock = 0

if stock != 0:
  money += stock * a[n-1]
print(money)