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

ud = [0] * (N-1)
for i in range(1,N):
    if A[i] > A[i-1]:
        ud[i-1] = 1
    if A[i] < A[i-1] :
        ud[i-1] = -1
    else:
        continue
        
tmp =0
bs = [''] * N
if ud[0] == 1:
    bs[0] = 'b'
    tmp = 1
if ud[0] == -1:
    tmp = -1

for i in range(1,len(ud)):
    if tmp == 0 and ud[i] != 0:
        tmp = ud[i]
    elif ud[i] == 0:
        continue
    elif tmp == -1 and ud[i] == 1:
        bs[i] = 'b'
        tmp = ud[i]
    elif tmp == 1 and ud[i] == -1:
        bs[i] = 's'
        tmp = ud[i]

bs[-1] = 's'

kabu = 0
zan = 1000
for i in range(N):
    if bs[i] == 'b':
        kabu = zan // A[i]
        zan -= kabu * A[i]
    if bs[i] == 's':
        zan += kabu * A[i]
        kabu = 0
print(max(1000,zan))

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
  maxind = 0
  minind = 0
  n = int(input())
  sp = list(map(int,input().split()))
  mxp = 0
  msf = sp[0]
  for i in range(1,n):
    d = sp[i] - msf;
    if (d > mxp):
      mxp = d
      maxind = i
    if(sp[i] < msf):
      msf = sp[i]
      minind = i
  a = 1000%sp[minind]
  b = 1000//sp[minind]
  a=a+b*sp[maxind]
  if(minind < maxind):
    print(a)
    exit()
  else:
    print("1000")

Submission status: Wrong Answer

Solution code:
NN = int(input())
A = list(map(int,input().split()))
money = 1000
n_of_kabu = 0
slope = [0] * (NN-1)
action = ['hold'] * (NN-1)
for i in range(NN-1):
    if A[i+1] >= A[i]:
        slope[i] = 1
    elif A[i+1] < A[i]:
        slope[i] = -1
    else:
        slope[i] = 0
#print(slope)

mymin = min(A[0:NN-1])
mymax = max(A[0:NN-1])
if (A[0] == mymin) & (A[0] <= A[NN-1]):
    action[0] = 'buy'

for i in range(1,NN-1):
    if (slope[i] == -1) and (slope[i-1] == 1):
        action[i] = 'sell'
    elif (slope[i] == 1) and (slope[i-1] == -1):
        action[i] = 'buy'
#print(action)

for i in range(NN-1):
    if action[i] == 'buy':
        add_n_of_kabu = int(money/A[i])
        money = money - add_n_of_kabu * A[i]
        n_of_kabu = n_of_kabu + add_n_of_kabu
    elif action[i] == 'sell':
        money = money + n_of_kabu * A[i]
        n_of_kabu = 0
#    print(money, n_of_kabu, A[i])
print(money + n_of_kabu * A[NN-1])

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
an=[]
for i in range(1,n):
    if a[i]>a[i-1]:
        an.append(a[i-1])
        break
pm=0
for j in range(i,n):
    #print(pm)
    if pm==0:
        if a[j]>=a[j-1]:
            if j==n-1:
                an.append(a[j])
            continue
        else:
            an.append(a[j-1])
            pm=1
            if j==n-1:
                an.append(a[j])
    else:
        if a[j]<=a[j-1]:
            continue
        else:
            an.append(a[j-1])
            pm=0
            if j==n-1:
                an.append(a[j])
#print(an)
ans=1000
k=0
for i in range(len(an)):
    if i%2==0:
        k=ans//an[i]
        ans-=k*an[i]
    else:
        ans+=k*an[i]
        k=0
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
an=[]
for i in range(1,n):
    if a[i]>a[i-1]:
        an.append(a[i-1])
        break
pm=0
for j in range(i,n):
    #print(pm)
    if pm==0:
        if a[j]>=a[j-1]:
            if j==n-1:
                an.append(a[j])
            continue
        else:
            an.append(a[j-1])
            pm=1
    else:
        if a[j]<=a[j-1]:
            continue
        else:
            an.append(a[j-1])
            pm=0
            if j==n-1:
                an.append(a[j])
#print(an)
ans=1000
k=0
for i in range(len(an)):
    if i%2==0:
        k=ans//an[i]
        ans-=k*an[i]
    else:
        ans+=k*an[i]
        k=0
print(ans)

Submission status: Wrong Answer

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

def purchase(kabuka, money):
    kabu = money // kabuka
    money -= kabu* money
    return kabu

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

min_kabuka = a[0]
max_kabuka = a[0]

def minmax(min_kabuka, max_kabuka, kabuka, money, kabu):
    flg = 0
    if min_kabuka >= kabuka:
        min_kabuka = kabuka
        flg = 1
    elif max_kabuka <= kabuka:
        max_kabuka = kabuka
        flg = 2
    
    if flg == 1:
        kabu = money // kabuka
        money -= kabu* money
    elif flg == 2:
        money = kabuka * kabu
        kabu = 0
    return money, kabu
for i in range(n):
    money, kabu = minmax(min_kabuka, max_kabuka, a[i], money, kabu)
if money <= 1000:
    print(1000)
else:
    print(money)

Submission status: Wrong Answer

Solution code:
N=int(input())
A = list(map(int,input().split()))
cc =0#株の数
cash =1000
bd =[0]*N#買う日
sd =[0]*N
for i in range(N):
  j =0
  while A[i] >= A[i+j]:
    bd[i] =i
    bd[i+j]=-1
    j = j+1
    if i+j >N-1:
      break
  k =0
  while A[i] <= A[i+k]:
    sd[i] =i+1
    sd[i+k]=-1
    k = k+1
    if i+k >N-1:
      break
if A[N-1] >A[N-2]:
  bd[N-1] = N
if A[N-1] < A[N-2]:
  sd[N-1] = N
sf = sorted(bd)[N-1]
for i in range(N):
  if bd[i]>0:
    if cc >0:
      cash =cash + cc*A[i]
      cc = 0
      print(cash)
  if sd[i]>0:
    cc = cash // A[i]
    cash = cash % A[i]

print(cash)
print(bd)
print(sd)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = 2
ARR = [157, 193]

N = 6
ARR = [200, 180, 160, 140, 120, 100]

N = 7
ARR = [100, 130, 130, 130, 115, 115, 150]

N = int(input())
ARR = list(map(int, input().split()))
#

# N = 5
# ARR = [111, 111, 111, 111, 111]

def calculate(arr):
    n = len(arr)
    result = []
    for i in range(n):
        if i == n-1:
            if arr[i] > arr[i-1]:
                result.append({'type': 1, 'value': arr[i]})
            if arr[i] < arr[i-1]:
                result.append({'type': 0, 'value': arr[i]})
            continue

        if i == 0:
            if arr[1] > arr[0]:
                result.append({'type': 0, 'value': arr[i]})
            if arr[1] < arr[0]:
                result.append({'type': 1, 'value': arr[i]})
            continue

        if (arr[i + 1] > arr[i]) and (arr[i] < arr[i - 1]):
            result.append({'type': 0, 'value': arr[i]})

        if (arr[i + 1] < arr[i]) and (arr[i] > arr[i - 1]):
            result.append({'type': 1, 'value': arr[i]})

    money = 1000
    num = 0
    history = []
    for res in result:
        type = res.get('type')
        value = res.get('value')
        if type == 0:
            tmpNum = money // value
            num += tmpNum
            money -= value * tmpNum
        else:
            money += num * value
            history.append(money)
            num = 0

    if len(history) == 0:
        print(money)
    else:
        print(max(history))

calculate(ARR)

Submission status: Wrong Answer

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

print(int(m))

Submission status: Wrong Answer

Solution code:
# vim: fileencoding=utf-8


def main():
    n = int(input())
    li = list(map(int, input().split()))

    money = 1000
    stock = 0
    for i in range(n):
        today = li[i]
        max = today
        min = today

        sell = False
        buy = False

        # 株を買う場合
        if money > 0 and money >= today:
            for j in range(i + 1, n):
                target = li[j]
                if today > target:
                    break
                if today < target:
                    buy = True
                    break
        if buy:
            c = int(money / today)
            stock += c
            money -= c * today

            continue

        # 株を売る場合
        if stock > 0:
            min = today
            max = today
            for j in range(i + 1, n):
                f = li[j]
                if today < f:
                    max = f
                    break
                if min > f:
                    min = f
            if max == today:
                sell = True
            else:
                tm = money + stock * today
                ts = int(tm / min)
                if ts > stock:
                    sell = True
            if sell:
                money += stock * today
                stock = 0

    print(money)


if __name__ == "__main__":
    main()

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
            dp[i][j] = max(dp[i][j], dp[i - 1][j + k] + a[i] * k)
    print(dp[i])
ans = max(dp[-1])
print(max(ans, 1000))
    # return max(ans, 1000)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
money=1000
kabu=0
newkabu=0
for i in range(n):
    if not max(a) == a[0]:
        newkabu = money//a[0]
        kabu += newkabu
        money -= a[0] * newkabu
    if newkabu ==0:
        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 = [int(x) for x in input().split()]

dif = [0 for _ in range(N)]
for i in range(1, N):
    if A[i-1] < A[i]:
        dif[i] = 1
    elif A[i-1] > A[i]:
        dif[i] = -1
    else:
        dif[i] = dif[i-1]

now = 0
kai, uri = set(), set()
for i in range(1, N):
    if now != dif[i]:
        if dif[i] == 1:
            uri.add(i)
            now = 1
        elif dif[i] == -1:
            kai.add(i)
            now = -1
#print(min(kai,default=0))
if min(uri,default=0) < min(kai,default=0):
    kai.add(0)
if max(kai,default=0) > max(uri,default=0):
    kai.remove(max(kai))
amar = 1000
kabu = 0


if len(uri) == 0:
    print(amar)

if len(kai) == 0:
    kabu = amar//A[0]
    amar = amar - kabu * A[0]
    amar = amar + kabu * A[1]
    kabu = 0
    print(amar)

else:

    for i in range(N):
        if i in kai:
            kabu = amar//A[i]
            amar = amar - kabu * A[i]
        if i in uri:
            amar = amar + kabu * A[i]
            kabu = 0
    print(amar)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[0]*N
A=list(map(int,input().split()))
money=1000
money_temp=1000
kazu=0
ma=0
stop=0
for i in range(0,N-1):
    if(A[i]<A[i+1]):
        money=money+kazu*ma
        kazu=money//A[i]
        money_temp=max(money_temp,money-A[i]*kazu)
        money=money-A[i]*kazu
        #print('ue')
        #print(A[i])
        #print(A[i+1])
    elif(A[i]==A[i+1]):
        pass
    elif(A[i+1]<A[i]):
        stop=1
        ma=max(A[i],ma)

money=money+kazu*A[N-1]

print(max(money,money_temp))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 1000
joushou = (a[0] < a[1])
kabu = 0
if joushou:
    zzz = 1000 // a[0]
    kabu += zzz
    ans -= zzz * a[0]

for i in range(1, n - 1):
    if joushou and a[i] > a[i + 1]:
        zzz = ans // a[i]
        kabu += zzz
        ans -= zzz * a[i]
        joushou = False
    elif not joushou and a[i] < a[i + 1]:
        ans += kabu * a[i+1]
        kabu = 0
        joushou = True


print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
MAX = 10


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
            dp[i][j] = max(dp[i][j], dp[i - 1][j + k] + a[i] * k)
    print(dp[i])
ans = max(dp[-1])
print(max(ans, 1000))
    # return max(ans, 1000)

Submission status: Wrong Answer

Solution code:
import math

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

a = A[0]
b = 0
c = 0
d = 1000

if a < A[1]:
    c = math.floor(d/a)
    d = d - (a*c)
    b = 1

for i in range(1,N-1):
    if b == 0:
        if A[i-1] > A[i] and A[i+1] >= A[i]:
            c = math.floor(d/A[i])
            d = d - (A[i]*c)
            b = 1
    else:
        if A[i-1] <= A[i] and A[i+1] < A[i]:
            d = d + (A[i]*c)
            c = 0
            b = 0
            
if A[N-2] < A[N-1]:
    d = d + (A[N-1]*c)

print(d)

Submission status: Wrong Answer

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

money=1000

chart=[a[0]]
flag=0

for i in range(n):
    if flag==0:
        if a[i]>chart[-1]:
            chart.append(a[i])
            flag=1

    else:
        if a[i]<chart[-1]:
            cnt=0
            M=0
            for j in range(i, n):
                if a[i]<a[j]:
                    cnt+=1
                    if M<a[j]:
                        M=a[j]
            
            if cnt==0:
                break
            elif cnt==1:
                chart.append(M)
                break
            else:
                flag=0

days=len(chart)

for day in range(days):
    if day%2==0:
        contact=money//chart[day]
        money-=contact*chart[day]
    
    else:
        money+=contact*chart[day]

    print(money, contact)

print(chart)
print(money)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(input().split())
a = [int(s) for s in a]
a.append(0)
money = 1000
kabuka = 0
kabusu = 0
for i in range(n):
    #買う
    if a[i] < a[i+1]:
        kabusu = kabusu + money // a[i]
        if money // a[i] > 0: 
            money = money - a[i]*kabusu
            kabuka = a[i]
    #売る
    if a[i] > kabuka:
        money = money + a[i]*kabusu
        kabusu= 0
 
print(money)

Submission status: Wrong Answer

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

a=list(dict.fromkeys(a))

b = [0] * (len(a)+1)
b[0] = 1000
c = [0] * (len(a) + 1)

print(a)
for i in range(len(a)):
    if i % 2 == 0:
        b[i+1] = b[i] - (b[i] // a[i]) * a[i]
        c[i] += b[i] // a[i]
    else:
        b[i + 1] += c[i - 1] * a[i]

print(max(b))

Submission status: Wrong Answer

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

movements = ['bull' if A[i+1]>A[i] else 'bear' for i in range(N-1)]
movements.append('bear')
movements.insert(0, 'bear')

money = 1000
stock = 0
for i in range(1, N+1):
    if movements[i-1] == 'bear' and movements[i] == 'bull':
        stock = money // A[i-1]
        money = money % A[i-1]
    elif stock > 0:
        money += A[i-1] * stock
        stock = 0
    else:
        pass

print(money)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
money = 1000
start = 0
while True:
    for i in range(start,N):
        if A[i] > A[start]:
            print(i)
            stock = money // min(A[start:i])
            amari = money % min(A[start:i])
            for j in range(i,N):
                if j == N-1:
                    money = amari + stock*max(A[i:j+1])
                    print(money)
                    exit()
                if A[j] < A[i] or j == N-1:
                    money = amari + stock*max(A[i:j])
                    stock = 0
                    amari = 0
                    start = j
                    break
            break
    continue

Submission status: Wrong Answer

Solution code:
n=int(input())
I=list(map(int,input().split()))
num=1000
if max(I)==I[0]:
    print("1000")
    exit()
for i in range(1,n):
    if I[i-1]<I[i]:
        num-=(num//I[i-1])*I[i-1]
        num+=(num//I[i-1])*I[i]

print(num)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
h = 0
m = 1000
for i in range(n):
    if i==0 and a[1]>a[0]:
        h1 = m//a[i]
        h += h1
        m -= a[i] * h1
    elif i==n-1:
        m += a[i] * h
        h = 0
    else:
        if a[i+1] > a[i] and a[i] > min(a[i+1::]) or a[i] > max(a[i+1::]):
            m += a[i] * h
            h = 0
        elif a[i+1] < a[i]:
            h1 = m//a[i]
            h += h1
            m -= a[i] * h1

print(m)

Submission status: Wrong Answer

Solution code:
n = int(input())
a_list = list(map(int,input().split()))
check_list = [0 for i in range(n)]
high_price = 0
row_price = a_list[0]
price = 1000
for i in range(1,n):
  if a_list[i] < a_list[i-1]:
    check_list[i] = "down"
  elif a_list[i] == a_list[i-1]:
    check_list[i] = "stay"
  else:
    check_list[i] = "up"  
hoge = "down" 
hoge_idx = 0
new_check_list = [0]
for i in range(1,n):
  if check_list[i] == hoge:
    new_check_list[-1] = "stay"
    new_check_list.append(hoge) 
  else:
    hoge = check_list[i]
    hoge_idx = i
    new_check_list.append(hoge)
down_price = a_list[0]
for i in range(1,n):
  if new_check_list[i] == "down":
    down_price = a_list[i]
  if new_check_list[i] == "up":
    stock = price // down_price
    amari = price - stock * down_price
    price = stock * a_list[i] + amari

print(price)

Submission status: Wrong Answer

Solution code:
_ = int(input())
kakaku = list(map(int, input().split()))

money = 1000
num_item = 0

if kakaku[0] < kakaku[1]:
    down_flag =False
    up_flag = True
else:
    up_flag=False
    down_flag = True

dp = []

if up_flag:
    dp.append(kakaku[0])

for i in range(1, len(kakaku)):
    if kakaku[i - 1] > kakaku[i]:
        if down_flag:
            pass
        else:
            down_flag=True
            up_flag=False
            dp.append(kakaku[i-1])
        down_flag = True
    elif kakaku[i-1] < kakaku[i]:
        if up_flag:
            pass
        else:
            down_flag = False
            up_flag = True
            dp.append(kakaku[i-1])
        up_flag = True

if kakaku[-2] < kakaku[-1]:
    if len(dp) >= 3 and kakaku[-3] < kakaku[-2]:
        dp[-1] = kakaku[-1]
    else:
        dp.append(kakaku[-1])

for i in range(len(dp)):
    if i % 2 == 0:
        num_item += money // dp[i]
        money -= dp[i] * num_item
    else:
        money += dp[i] * num_item
        num_item = 0
if num_item != 0:
    money += num_item * dp[-1]

print(money)

Submission status: Wrong Answer

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

max_index = [i for i, x in enumerate(A) if x == max(A)]
stopbuy = max_index[-1]

money = 1000
stock = 0

for i in range(stopbuy):
    if A[i+1] > A[i]:
        stock = money // A[i]
        money = money % A[i]
    else: # A[i+1] <= A[i]
        money = money + A[i] * stock
        stock = 0

money = money + A[stopbuy] * stock
print(money)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
mon = 1000
kabu = 0
diff = 0
maa = 0
minn = 0
out = 0
tmp = 0
if A[-1] == 100:
  print("1000")
else:
  mins = A[0]
  maxs = 0
  for i in range(N-1): 
    a = A[i+1:]
    amax = max(a)
    tmp = amax-A[i]
    if diff <= tmp :
      maxin = A.index(amax)
      minin = i
      maa = amax
      minn = A[i]
  kabu = mon / maa
  mon = mon % maa
  mon += maa * kabu 
  print(int(mon))

Submission status: Wrong Answer

Solution code:
import copy
from collections import deque


# def fig(A):
#     x = np.array(range(len(A)))
#     y = np.array(A)
#     plt.plot(x, y)
#     plt.show()


def buy(money, A, stock):
    stock += money // A
    money %= A
    return money, stock


def sell(money, A, stock):
    money += stock * A
    return money, 0


def do_both(money, A0, A1, stock):
    money, stock = buy(money, A0, stock)
    money, stock = sell(money, A1, stock)
    return (money, stock)


def shaping(A):
    # 連続値を削除
    B = A[:1]
    for a in A[1:]:
        if B[-1] != a:
            B.append(a)
    # 上昇あるいは下降の途中値を削除
    A = copy.copy(B)
    B = A[:1]
    for i in range(1, len(A)-1):
        if not (A[i-1] < A[i] < A[i+1] or A[i-1] > A[i] > A[i+1]):
            B.append(A[i])
    B.append(A[-1])
    # 最初と最後を調整
    A = copy.copy(B)
    #   最初よりその次のほうが低ければ、その次を開始地点とする
    try:
        if A[1] < A[0]:
            A = A[1:]
    except:
        pass
    #   最後よりその前のほうが高ければ、その前を終了地点とする
    try:
        if A[-2] > A[-1]:
            A = A[:-1]
    except:
        pass
    # (下, 上)のタプルに変換して返す
    return [(A[i], A[i+1]) for i in range(0, len(A)-1, 2)]


def bfs(q, A, i):
    if i >= len(A):
        return q
    money, stock = q.popleft()
    q.append(do_both(money, *A[i], 0))
    q.append((money, stock))
    return bfs(q, A, i+1)


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

    A = shaping(A)
    q = deque()
    if len(A) == 0:
        print(1000)
        exit()
    q.append(do_both(1000, *A[0], 0))
    q.append((1000, 0))
    q = bfs(q, A, 1)

    ans = 0
    for a in q:
        if a[0] >= ans:
            ans = a[0]

    print(ans)

Submission status: Wrong Answer

Solution code:
N = 2
ARR = [157, 193]

N = 6
ARR = [200, 180, 160, 140, 120, 100]

N = 7
ARR = [100, 130, 130, 130, 115, 115, 150]

N = int(input())
ARR = list(map(int, input().split()))
#

# N = 5
# ARR = [111, 111, 111, 111, 111]

def calculate(arr):
    n = len(arr)
    result = []
    for i in range(n):
        if i == n-1:
            if arr[i] > arr[i-1]:
                result.append({'type': 1, 'value': arr[i]})
            if arr[i] < arr[i-1]:
                result.append({'type': 0, 'value': arr[i]})
            continue

        if i == 0:
            if arr[1] > arr[0]:
                result.append({'type': 0, 'value': arr[i]})
            if arr[1] < arr[0]:
                result.append({'type': 1, 'value': arr[i]})
            continue

        if (arr[i + 1] > arr[i]) and (arr[i] < arr[i - 1]):
            result.append({'type': 0, 'value': arr[i]})

        if (arr[i + 1] < arr[i]) and (arr[i] > arr[i - 1]):
            result.append({'type': 1, 'value': arr[i]})

    money = 1000
    num = 0
    history = []
    for res in result:
        type = res.get('type')
        value = res.get('value')
        if type == 0:
            num += money // value
            money -= num * value
        else:
            money += num * value
            history.append(money)
            num = 0

    if len(history) == 0:
        print(money)
    else:
        print(max(history))

calculate(ARR)

Submission status: Wrong Answer

Solution code:
from collections import deque
n = int(input())
a = list(map(int,input().split()))
stack = deque()
stack.append([1000,0,0,200])
ans = []
while stack:
  money,kabu,i,temp = stack.pop()
  ans.append(money)
  if i<n:
    if a[i]<temp and a[i]<=money:
      kabu += money//a[i]
      money %= a[i]
      stack.append([money,kabu,i+1,a[i]])
    elif a[i]>temp and kabu>=1:
      money += a[i]*kabu
      kabu = 0
      stack.append([money,kabu,i+1,a[i]])
    else:
      stack.append([money,kabu,i+1,a[i]])
    ans.append(money)
print(max(ans))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
A = list(map(int, input().split()))

money = 1000
stock = 0

i = 0
while i < N:
  A_min = A[i]
  A_max = A[i]
  A_min_index = i
  A_max_index = i
  for j in range(i, N):
    if A[j] < A_min:
      A_min = A[j]
      A_min_index = j
    if A[j] > A_max:
      A_max = A[j]
      A_max_index = j
      if A_min != 201:
        # 株購入
        stock = money // A[A_min_index]
        money = money % A[A_min_index]
        
        # 株売却
        money += stock * A[A_max_index]
        stock = 0
        i = A_max_index
        break
  i += 1
print(money)

Submission status: Wrong Answer

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

#print(N)
#print(A)

syozi = 1000
kabu = 0

for i in range(N):
#  print(str(i)+': '+ str(A[i]) + ', ' + str(kabu) + ', ' + str(syozi) )
  if i == N-1:
    syozi += A[i] * kabu
    kabu = 0
  elif A[i] < A[i+1]:
    kabu = int( syozi / A[i] )
    syozi = int( syozi % A[i] )
  elif A[i] > A[i+1]:
    syozi += A[i] * kabu
    kabu = 0
  else:
    pass
#  print( str(i)+': '+str(A[i]) + ', ' + str(kabu) + ', ' + str(syozi) )

print(syozi)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
money  = 1000
stock = 0
min_price = 200
max_price = 100

for i in range(n):
    if a[i] <= min_price:
        min_price = a[i]
    else:
        if a[i] >= max_price:
            max_price = a[i]
            if i == n - 1:
                money = (money // min_price) * max_price + money % min_price
        else:
            money = (money // min_price) * max_price + money % min_price
            min_price = a[i]
            max_price = a[i]
print(money)

Submission status: Wrong Answer

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

money = 1000
num = 0
buy_p = 0
i = 0

while i < N-1:
    if A[i] >= A[i+1]:
        i += 1
        continue
    elif i == N-2:
        if A[i] < A[N-1]:
            num, money = divmod(money, A[i])
            money += A[N-1] * num
        break
    for j in range(i+2, N):
        if A[j-1] > A[j]:
            num, money = divmod(money, A[i])
            money += A[j-1] * num
            i = j + 1
            break

print(money)

Submission status: Wrong Answer

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 A[i] < np.max(A[i:]):
            if A[i] > np.min(A[i:]) and np.argmin(A[i:]) < np.argmax(A[i:]):
                continue
            else:
                have_money, have_stock, have_stock_valuation = buy_stock(have_money, have_stock, have_stock_valuation, A[i])
                call_status = False
    else:
        if have_stock_valuation / have_stock < A[i]:
            try:
                if A[i] < A[i+1]:
                    continue
                else:
                    have_money, have_stock, have_stock_valuation = sell_stock(have_money, have_stock, have_stock_valuation,  A[i])
                    call_status = True
            except:
                have_money, have_stock, have_stock_valuation = sell_stock(have_money, have_stock, have_stock_valuation,  A[i])
                call_status = True

print(have_money)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10**8)

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

def rec(k, ans, money, n):

    x = a[k]
    for i in range(k+1, len(a)):
        if (x < a[i]):   # 買う
            n = money // a[i-1]
            money -= a[i-1] * n
            money += a[i] * n
            rec(i, ans, money, n)

    return ans.append(money)

def main():
    ans = [0]
    money = 1000
    n = 0
  
    rec(0, ans, money, n)
    print(max(ans))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ans = 1000
maxv = a[0]
minv = a[0]
for i in range(1, n):
    if i < n - 1:
        if a[i] < maxv:
            ans += (maxv - minv) * (ans // minv)
            maxv = a[i]
            minv = a[i]
        else:
            maxv = max(maxv, a[i])
            minv = min(minv, a[i])
    else:
        if a[i] > minv:
            ans += (a[i] - minv) * (ans // minv)

print(ans)