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()))
money=1000
stock=0
buy=0
flag=0
sell=300
if A[0]==max(A):
  print(money)
else:
  for i in range(n):
    if A[i]>buy and stock>0:
      money+=stock*A[i]
      stock=0
      sell=A[i]
      if sell==max(A[i:n+1]):
        flag=1
    elif A[i]<sell and flag==0 and A[i]<max(A[i:n+1]):
      stock=money//A[i]
      money-=stock*A[i]
      buy=A[i]
      sell=0
  print(money)

Submission status: Wrong Answer

Solution code:
N = int(input())
lst = list(map(int, input().split()))
bs = [0]*N
stock = 0
money = 1000

for i in range(1, N):
    if lst[i-1] < lst[i]:
        bs[i-1] = 1
        if i > 1 and bs[i-2] == 1:
            bs[i-1] = -1

for i in range(N):
    if bs[i] == 1:
        stock = money // lst[i]
        money = money % lst[i]
    elif bs[i] == 0 and stock > 0:
        money += stock * lst[i]
        stock = 0
    elif bs[i] == -1 and i == N-1 and stock > 0:
        money += stock * lst[i]
        stock = 0

print(money)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
value = 1000
current = 0
stocks = 0
if A[0] == max(A):
    print(1000)
else:
    for i in range(N-1):
        if A[i] < A[i+1] :
            h = value//A[i]
            stocks+=h
            value = value - h*A[i]
        if A[i]==max(A[i:]) :
            value = value + stocks*A[i]
            stocks = 0
        elif A[i] > A[i+1]:
            value = value + stocks*A[i]
            stocks = 0
    
    value = value + stocks*A[N-1]
    print(value)

Submission status: Wrong Answer

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

ls = []
if A[0] < A[1]:
  ls.append(A[0])
for i in range(1,N-1):
  if A[i] == A[i-1]:
    continue
  elif A[i-1] < A[i] < A[i+1]:
    continue
  elif A[i-1] > A[i] > A[i+1]:
    continue
  ls.append(A[i])  
if A[-1] > A[-2]:
  ls.append(A[-1])
  
if ls == []:
  print(1000)
else:
  for i,j in enumerate(ls):
    if i%2 == 0:
      stock += my_money//j
      my_money %= j
    else:
      my_money += stock*j
      stock = 0
  print(my_money)

Submission status: Wrong Answer

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

money = 1000
stock = 0
if A[0] < A[1]:
    stock += (money//A[0])
    money %= A[0]
    
tmp = A[0]
cnt = 1

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.append(0)
m=1000
s=0
for i in range(n):
    if a[i]<a[i+1]:
        s=m // a[i]
        m=m % a[i]
    elif a[i] >= a[i+1]:
        m=m + s * a[i]
        s=0
    else:
        pass
print(m)

Submission status: Wrong Answer

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

money = 1000
num_item = 0

up_flag = False
down_flag = False

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

dp = []

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

# 減=>増=>減....の形にする
for i in range(1, len(kakaku)):
    # いま増加中or下後中
    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
    # print('up', up_flag, 'down', down_flag, 'now item',kakaku[i], 'dp', dp)

if kakaku[-2] < kakaku[-1]:
    dp.append(kakaku[-1])

if len(dp) == 1:
    print(1000)

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 += dp[-1] * num_item

print(money)

Submission status: Wrong Answer

Solution code:
terms = int(input())
values = [int(i) for i in input().split(" ")]

newValues = []
tempValue = 0
trend = ""

for i in range(terms):
    if i == 0:
        newValues.append(values[i])
        tempValue = values[i]
    elif i == terms - 1:
        if (trend == "U" and tempValue > values[i]) or (trend == "D" and tempValue < values[i]):
            newValues.append(tempValue)
            newValues.append(values[i])
        elif (trend == "U" or trend == "") and tempValue < values[i]:
            newValues.append(values[i])
    elif trend == "":
        if tempValue > values[i]:
            tempValue = values[i]
            trend = "D"
        elif tempValue < values[i]:
            tempValue = values[i]
            trend = "U"
    else:
        if trend == "U" and tempValue > values[i]:
            newValues.append(tempValue)
            tempValue = values[i]
            trend = "D"
        elif trend == "D" and tempValue < values[i]:
            newValues.append(tempValue)
            tempValue = values[i]
            trend = "U"

baseWealth = [1000,0]

for i in range(len(newValues) - 1):
    if newValues[i] < newValues[i+1]:
        baseWealth[1] = baseWealth[0] // newValues[i]
        baseWealth[0] = baseWealth[0] % newValues[i]
    else:
        baseWealth[0] = baseWealth[0] + baseWealth[1] * newValues[i]
        baseWealth[1] = 0
baseWealth[0] = baseWealth[0] + baseWealth[1] * newValues[len(newValues) - 1]
baseWealth[1] = 0

print(baseWealth[0])

Submission status: Wrong Answer

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

money = 1000
stock = 0
leave_max = max(a[1:])

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

    leave_max = max(a[i+1:])

    if a[i] >= a[i+1]:
        if stock != 0:
            money += a[i] * stock
            stock = 0

        if a[i] > leave_max:
            break
        else:
            continue

    elif a[i] < a[i+1]:
        num = money // a[i]
        if num != 0:
            stock += num
            money -= stock * a[i]

print(money)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))
m = 1000
kabu = 0
buy = True

for i in range(len(a)-1):
    if buy and np.any(a[i] < a[i+1:]):
        kabu = int(m/a[i])
        m -= kabu * a[i]
        buy = False
    elif not buy and np.any(a[i] > a[i+1:-1]):
        m += kabu * a[i]
        kabu = 0
        buy = True
    else:
        continue

if kabu != 0:
    m += kabu * a[-1]

print(m)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
money = 1000
stock = 0
tmp = [0]*(N-1)

for i in range(N-1):
    if A[i] == A[i+1]:
        tmp[i] = 0
    else:
        if A[i] < A[i+1]:
            tmp[i] = 1
        else:
            tmp[i] = -1

for i in range(N-1):
    if tmp[i] == 1:
        stock += money//A[i]
        money -= A[i]*stock
    if tmp[i] == -1:
        money += A[i]*stock
        stock = 0
    if tmp[i] == 0:
        continue
    # print('day',i+1,':',money,stock)


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

Submission status: Wrong Answer

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

sum = 1000
kabu = 0

for k in range(K):
    if k+1 ==K:
        sum +=kabu*A[K-1]
        break
    if A[k]<A[k+1] and A[k]<=sum:
        S = int(sum/A[k])
        sum = sum-A[k]*S
        kabu +=S
    elif A[k]>A[k+1] and kabu != 0:
        sum = sum + kabu * A[k]
        kabu = 0
    print(sum)
    

print(sum)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    A = [int(x) for x in input().split()]
    money = 1000
    kabu_c = 0
    l = list()
    for i in range(n-1):
        if A[i+1] - A[i] > 0:
            l.append(1)
        else:
            l.append(0)
    for idx, i in enumerate(l):
        if i == 1:
            kabu_c = money // A[idx]
            money = money - (kabu_c * A[idx])
        if i == 0:
            money = money + (kabu_c * A[idx])
            kabu_c = 0
    if kabu_c > 0:
        money = money + (kabu_c * A[n-1])
    print(money)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

stock = [0]*n
score = 1000
for i in range(len(A)):
    #print(i)
    if i != len(A)-1:
        if A[i] < A[i+1]:
            stock[i] = score // A[i]
            score -= ((score // A[i]) * A[i])
        
    if i != 0:
        if A[i-1] < A[i]:
            score += stock[i-1]*A[i]
            stock[i-1] = 0
    #print(stock)
    #print(score)
print(score)

Submission status: Wrong Answer

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
from fractions  import gcd
#input=sys.stdin.readline
import bisect
n=int(input())
a=list(map(int,input().split()))
i=0
m=1000
f=True
k=0
M=[1000]

for s in range(1,n):
    if a[s]>a[i]:
      break
    i=s 
while True:
    if i==n-1:
        break
    if f:
        for j in range(i+1,n):
            if a[j]>a[i]:
                check=True
                x=j
                for l in range(j+1,n):
                    if a[l]<a[j]:
                        break
                    else:
                        x=l
                if check:
                    m=(m//a[i])*a[x]+(m%a[i])
                    i=x
                    M.append(m)
                    f=False
                    break
        else:
            break
    else:
        for j in range(i+1,n):
            if a[j]<a[i]:
                x=j
                for l in range(j+1,n):
                    if a[l]>a[j]:
                        break
                    else:
                        x=l
                i=x
                f=True
                break
        else:
            break
print(max(M))

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = list(map(int,input().split()))
    ans = 1000
    for i in range(n-1):
        m = 1000
        ls = [0 for i in range(n)]
        ls[i] = 1
        l = i
        for j in range(i+1,n):
            if a[j]>a[l]:
                ls[j] = 1
                if j>0:
                    if ls[j-1]==1:
                        ls[j-1]=0
                l = j
            elif a[l]>a[j]:
                ls[j] = -1
                if j>0:
                    if ls[j-1]==-1:
                        ls[j-1] = 0
                l = j
            else:
                ls[j]=0
                l = j
        cnt = 1000//a[i]
        m = 1000-cnt*a[i]
        pt = 0
        for k in range(len(ls)):
            if ls[k]==1:
                m = m+cnt*a[k]
                cnt = 0
            elif ls[k]==-1:
                cnt = m//a[k]
                m = m-cnt * a[k]
                pt = k
        m = m+cnt*a[pt]
        if m>ans:
            ans = m
    print(ans)
                

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

ans=1000
kabu=0
flag=0

for i in range(n-1):
    if a[i]<a[i+1]:
        if flag !=1:
            kabu=int(ans/a[i])
            ans-=(kabu*a[i])
            #print(a[i],ans,kabu)
        flag=1
    elif a[i]>a[i+1]:
        if flag >0:
            ans+=(kabu*a[i])
            #print(ans)
        flag=-1
    else:
        if flag>0:
            flag=2
        else:
            flag=-2
    if i==(n-2) and flag>0:
        ans+=(kabu*a[i+1])
        #print(a[i+1],ans)

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
#n,k=map(int,input().split())
v=list(map(int,input().split()))
l=list()
prev=0
for i in v:
  if prev!=i:
    l.append(i)
    prev=i
n=len(l)
if n==1:
  print(1000)
else: 
  d=list()
  if l[0]>l[1]:
      d.append(l[0])
  if l[0]<l[1]:
      d.append(l[0])
  for i in range(1,n-1):
    if l[i-1]<l[i] and l[i+1]<l[i]:
      d.append(l[i])
    if l[i-1]>l[i] and l[i+1]>l[i]:
      d.append(l[i])
  if l[-1]>l[-2]:
      d.append(l[-1])
  if l[-1]<l[-2]:
      d.append(l[-1])
  #print(d)
  n=len(d)
  p=1000
  if n>1:
    for i in range(1,n,2):
      if d[i-1]<d[i]:
        z=(p//d[i-1])*d[i]
        r=p%d[i-1]
        if z+r>p:
        	p=z+r
    print(p)
  else:
    print(p)

Submission status: Wrong Answer

Solution code:
from copy import copy

def check_flag(num1,l):
    return num1 < max(l)

n = int(input())
A = list(map(int,input().split()))
money = 1000
stcok = 0
# 前回買った株
last = 201

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

    flag = check_flag(A[i],A[i+1::])
    if A[i] < last and flag:
        tmp = money//A[i]
        money -= A[i]*tmp
        stcok += tmp
        last = copy(A[i])
    elif last < A[i]:
        money += stcok * A[i]
        stcok = 0
        last = copy(A[i])

print(money)

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(201)
    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(max(1000, b))


if __name__ == "__main__":
    main()

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(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:
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(201)
    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)

    print(il)
    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, s)

        print(max(1000, b))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
k = int(input())
a = list(map(int,input().split()))
a.append(1)
a.append(0)

money = 1000
stock = 0

for i in range(k):
    if a[i] <= a[i+1] and money >= a[i]:
        stock += money//a[i]
        money -= a[i] * stock
        continue
    if a[i] >= a[i+1] and a[i] >= a[i+2]:
        money += a[i] * stock
        stock = 0
        continue
    else:
        continue
print(money)

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:
    break
  stack.append([money,kabu,i+1,temp])
  if a[i]<temp and a[i]<=money:
    kabu += money//a[i]
    money %= a[i]
  elif a[i]>temp and kabu>=1:
    money += a[i]*kabu
    kabu = 0
  stack.append([money,kabu,i+1,a[i]])
  ans.append(money)
print(max(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [0]+[int(x) for x in input().split()]
kabuka=[a[1]]
taka=True

for i in range(1,n+1):
    if taka:
        if kabuka[-1]<a[i]:
            kabuka.append(a[i])
            taka=False
    else:
        if kabuka[-1]>a[i]:
            kabuka.append(a[i])
            taka=True

money=1000
if len(kabuka)==1:
    print(money)
    exit()

for i in range(len(kabuka)):
    if i%2==0:
        if i==len(kabuka)-1:
            break
        kabukosuu=money//kabuka[i]
        money%=kabuka[i]
    else:
        money+=kabukosuu*kabuka[i]

print(money)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
pair = []
l = -1
r = -1
flg = False
for i in range(n-1):
    if flg == False:
        if a[i+1]-a[i]>=0:
            l = i
            flg = True
        else:
            pass
    else:
        if a[i+1]-a[i]>=0:
            pass
        else:
            r = i
            flg = False
            pair.append((a[l],a[r]))
if flg:
    r = i+1
    pair.append((a[l],a[r]))
# print(pair)
money = 1000
stock = 0
max_rate = 0
for fr,to in pair: 
    if to/fr > max_rate:
        max_rate = to/fr
        #
        buy = money//fr
        stock += buy
        money -= buy*fr
        #
        sold = stock
        money += sold*to
        stock -= sold
    else:
        continue
print(money)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))
m = 1000
kabu = 0
buy = True

for i in range(len(a)-1):
    if buy and np.any(a[i] < a[i+1:]):
        kabu = int(m/a[i])
        m -= kabu * a[i]
        buy = False
    elif not buy and np.any(a[i] > a[i+1:]):
        m += kabu * a[i]
        kabu = 0
        buy = True
    else:
        continue

if kabu != 0:
    m += kabu * a[-1]

print(m)

Submission status: Wrong Answer

Solution code:
n = int(input())
a_list = list(map(lambda x: int(x), input().split()))
possesion = 1000
num_stock = 0

# print(a_list)
for i in range(len(a_list) - 1):
    a_today = a_list[i]
    for a in a_list[i+1:]:
        if a != a_today:
            a_next = a
            break
        a_next = a
    # これからずっと値段が変わらない場合は全部売ってあと放置
    if a_next == a_today:
        possesion += num_stock * a_list[-1]
        exit()
    
    if a_today < a_next:
        # 買えるだけ買う
        possesion_yesterday = possesion
        possesion = possesion % a_today
        num_stock += possesion_yesterday // a_today
    if a_today > a_next:
        # うれるだけうる
        possesion += num_stock * a_today
        num_stock = 0
#     print(a_today, a_next, possesion, num_stock)

# 最終日は買えるだけ買う
possesion += num_stock * a_list[-1]
print(possesion)

Submission status: Wrong Answer

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

# 頂点を集める
edge = [a_list[0]]
now = a_list[0]
desc = True if a_list[0] > a_list[1] else False
i = 1
while i < len(a_list)-1:
  if desc:
    if now >= a_list[i+1]:
      now = a_list[i+1]
    else:
      edge.append(now)
      desc = False
  else:
    if now <= a_list[i+1]:
      now = a_list[i+1]
    else:
      edge.append(now)
      desc = True
  now = a_list[i+1]
  i+=1

if edge[0] <= edge[-1]:
  desc = False
else:
  desc = True
kabu = 0
money = 1000
for e in edge:
  if desc:
    money += kabu * e
    kabu = 0
  else:
    kabu = money//e
    money -= kabu * e
  desc = not desc

money += kabu * a_list[-1]

print(max(1000,money))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
kabu = 0
money = 1000
uri = 100
for i in range(N):
  if uri == i:
    money += A[j]*kabu
    kabu = 0
    continue
    
  for k in range(i+1, N):
    if A[k] > A[i]:
      kabu += money // A[i]
      money %= A[i]
      break
      
  for j in range(i+1, N):
    if j == N-1:
      uri = j
      break
      
    elif A[j+1] < A[j]:
      uri = j
      break
      
  if i == N:
    money += A[j]*kabu
    kabu = 0
  
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
kabu = 0
for i in range(n):
    if a[i] < a[i+1]:
        kabu = money // a[i]
        money = money - a[i]*kabu 
        kabuka = a[i]
        
    if a[i] > kabuka:
        money = money + a[i]*kabu
        kabu = 0
 
print(money)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(X) for X in input().split()]
Stock = 0
Money = 1000
for T in range(N-1):
    if A[T+1]>A[T]:
        Stock = Money//A[T]
        Money -= Stock*A[T]  
    elif A[T+1]<A[T]:
        Money += Stock*A[T]
        Stock = 0
if Stock>0:
    Money += Stock*A[N-1]
    Stock = 0
print(Money)

Submission status: Wrong Answer

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

stopbuy = A.index(max(A))

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())) 

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import os
from sys import stdin, stdout

n = 0
seq = []
dp = []

def getMaximum(idx, stock, money):
    if idx == n-1:
        return money + stock*seq[idx]

    if stock < 10000 and dp[idx][stock]>money:
        return 0

    ret = getMaximum(idx+1, stock, money)

    # buying
    k = 1
    cost = seq[idx]
    while cost <= money:
        ret = max(ret, getMaximum(idx+1, stock+k, money-cost))
        k += 1
        cost += seq[idx]

    # do nothing or selling
    cost = seq[idx]
    for k in range(1,stock):
        ret = max(ret, getMaximum(idx+1, stock-k, money+cost))
        cost += seq[idx]

    if stock < 10000:
        dp[idx][stock] = max(ret, dp[idx][stock])

    return ret


def solve(tc):
    global n
    global seq
    global dp

    n = int(stdin.readline().strip())
    seq = list(map(int, stdin.readline().split()))
    dp = [[-1 for j in range(10000)] for i in range(n)]

    print(getMaximum(0, 0, 1000))


tcs = 1
tc = 1
while tc <= tcs:
    solve(tc)
    tc += 1

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
money=1000
stock=0
buy=0
flag=0
sell=300
if A[0]==max(A):
  print(money)
else:
  for i in range(n):
    if A[i]>buy and stock>0:
      money+=stock*A[i]
      stock=0
      sell=A[i]
      if sell==max(A[i:n+1]):
        flag=1
    elif A[i]<sell and flag==0:
      stock=money//A[i]
      money-=stock*A[i]
      buy=A[i]
      sell=0
  print(money)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [0]+[int(x) for x in input().split()]
kabuka=[a[1]]
taka=True

for i in range(1,n+1):
    if taka:
        if kabuka[-1]<a[i]:
            kabuka.append(a[i])
            taka=False
    else:
        if kabuka[-1]>a[i]:
            kabuka.append(a[i])
            taka=True

money=1000
if len(kabuka)==1:
    print(money)
    exit()

for i in range(len(kabuka)):
    if i%2==0:
        if i==len(kabuka):
            break
        kabukosuu=money//kabuka[i]
        money%=kabuka[i]
    else:
        money+=kabukosuu*kabuka[i]

print(money)

Submission status: Wrong Answer

Solution code:
N = int(input())
List = list(map(int,input().split()))
sell = []
buy = []
Listvar = List[:]
while Listvar:
  max_value = max(Listvar)
  max_index = Listvar.index(max_value)
  sell.append(max_index)
  if max_index == 0:
    break
  while Listvar[max_index] >= Listvar[max_index-1]:
      max_index -= 1
  buy.append(max_index)
  Listvar = Listvar[:max_index]

if len(buy) != len(sell):
  print(1000)
else:
  ans = 1000
  stock = 0
  for i in range(len(buy)):
    temp = ans
    ans = temp % List[buy[-(i+1)]]
    stock += temp // List[buy[-(i+1)]]
    ans += stock*List[sell[-(i+1)]]
    stock = 0
  print(ans)

Submission status: Wrong Answer

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

money = 1000
stock = 0

for i in range(N-1):
    if A[i] < A[i+1]:
        stock = money // A[i]
        money = money - A[i] * stock
        # print("buy stocks; money=",money,", stock=",stock)
    else:
        money = money + A[i+1] * stock
        stock = 0
        # print("sell stocks; money=",money,", stock=",stock)

if stock != 0:
    # print("last;money stock",money,stock)
    # print(A[-1])
    money = money + A[-1] * stock
    stock = 0

# print("money=",money,", stock=",stock)

print(money)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import numpy as np

n = int(input())

AA = [int(a) for a in input().split()]
c = 0
updwn=[None]*(n-1)
for a in AA:
    if c ==0:
        c +=1
        base = a
        continue
    if a - base >= 0:
        updwn[c-1] = True
        base = a
    else:
        updwn[c-1] = False
        base = a
    c += 1
updwn+=[False, False]
base = False
total = 1000
stock = 0
if n ==2:
    if updwn[0]==True:
        total += (total//AA[0])*(AA[1]-AA[0])
else:
    for i in range(n-1):
        if updwn[i] == True and base == False:
            tdcost= AA[i]
            stock = total // tdcost
            base_cost = tdcost
        elif updwn[i] == True and updwn[i+1]==False:
            tdcost=AA[i+1]
            total += (tdcost - base_cost)*stock
            stock = 0
        else:
            pass
        base = updwn[i]
print(total)

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 #買う株は決まった
            ans -= cnt * buy
            sell = A[i] #売る時の株の値段
    else:
        if sell:
            ans += sell * cnt
            flg = True #株を売った
            sell = 0
            cnt = 0
        else: #買う株をできるだけ安いのにしたい
            buy = A[i]

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