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())
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 kakaku[0] > kakaku[1]:
    while True:
        pass

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

mon = 1000


for i in range(1, n):
	if a[i-1] < a[i]:
		kb = mon // a[i-1]
		mon %= a[i-1]
		mon += kb * a[i]
		print(kb, mon)

print(mon)

Submission status: Wrong Answer

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy

if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    have = 1000
    kabu = 0
    hoge = 0
    for i in range(n):
        flag = 0
        if kabu>0:
            if a[i-1] < a[i]:
                for j in range(kabu):
                    have += a[i]
                kabu = 0
            elif a[i-1] == a[i]:
                hoge +=1
            else:
                for j in range(i,n):
                    if a[j]>a[i]:
                        flag = 1
                        break
                if flag == 1:
                    n_have = have
                    for k in range(n_have//a[i]):
                        have-=a[i]
                        kabu+=1
        else:
            if a[i-1]==a[i] and i>0:
                continue
            for j in range(i,n):
                if a[j]>a[i]:
                    flag = 1
                    break
            if flag == 1:
                n_have = have
                for k in range(n_have//a[i]):
                    have-=a[i]
                    kabu+=1
    print(have)

Submission status: Wrong Answer

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


def full_purchase(kabuka):
    kabu = 1000 // kabuka
    return kabu

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

ans = 0
min_kabuka = min(a)
min_kabuka_index = a.index(min(a))

b = a
for i in range(len(b)):
    max_kabuka_index = b.index(max(b))
    if min_kabuka_index < max_kabuka_index:
        ans = sell(a[max_kabuka_index], full_purchase(a[min_kabuka_index]))
        if ans <= 1000:
            print(1000)
            exit()
        else:
            print(ans)
            exit()
    else:
        b.remove(max(b))
print(1000)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

mi = min(A)
ma = max(A)

for i in range(N):
    if mi == A[i]:
        mi_left = i

for i in range(N):
    if ma == A[N-i-1]:
        ma_right = N - i

B = A[mi_left:ma_right]
# print(B)
if len(B) == 0:
    print(1000)
    exit()
C = []
for i in range(len(B)-1):
    if B[i] == B[i+1]:
        continue
    C.append(B[i])
if B[-1] != B[-2]:
    C.append(B[-1])  

have = 1000
kabu_num = 0
for i, c in enumerate(C):
    if i % 2 == 0:
        kabu_num += have // c
        have = have - kabu_num * c
    else:
        # kabu_num -= 
        have += kabu_num * c
        # kabu_num -= 
        kabu_num = 0

          
print(have)

Submission status: Wrong Answer

Solution code:
import math

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

    # dp=[1]*202020
    # for i in range(K):
    #     dp[K]*=A[i]

    List = [[0 for j in range(N)] for i in range(N)]

    for i in range(N):
        for j in range(i,N):
            List[i][j]=A[j]-A[i]

    buy=False
    Kabu=0
    Yen=1000
    for i in range(N):
        isUp=True
        UpCnt=0
        DownStart=0
        for j in range(i+1,N):
            if(A[j]>A[i]):
                UpCnt+=1
            else:
                if(UpCnt==0):
                    DownStart=j
                    isUp=False
                    break
        if(i+1==N):
            isUp=False
        if(isUp and i>DownStart-1):
            if(buy==False):
                buy=True
                Kabu+=Yen//A[i]
                Yen-=A[i]*(Yen//A[i])
            else:
                buy=False
                Yen+=A[i]*Kabu
                Kabu=0

        else:
            if(buy==True):
                buy=False
                Yen+=A[i]*Kabu
                Kabu=0




    print(Yen)

resolve()

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

ans = money + stock*A[N-1]

print(ans)

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_today
    # これからずっと値段が変わらない場合は全部売ってあと放置
    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:
import sys

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

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

j = N

if A[j-2] < A[j-1]:
    pass
else:
    while(A[j-2] < A[j-1]):
        j -= 1

for i in range(j-1):
    
    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*A[j-1]
print(money)

Submission status: Wrong Answer

Solution code:
N=int(input())
souba=list(map(int,input().split()))
urikaiba=list()
money=1000
num=0
for i in range(1,N-1):
    if (souba[i]-souba[i-1])*(souba[i+1]-souba[i])<=0:
        urikaiba.append(souba[i])
urikaiba.insert(0,souba[0])
urikaiba.append(souba[N-1])
for i in range(len(urikaiba)-1):
    if urikaiba[i+1]-urikaiba[i]>0:
        num=money//urikaiba[i]
        money=money-num*urikaiba[i]
    elif urikaiba[i+1]-urikaiba[i]<0:
        money=money+num*souba[i]
        num=0
if num==0:
    print(money)
else:
    print(money+num*souba[N-1])

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_today
    # これからずっと値段が変わらない場合は全部売ってあと放置
    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(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 and i > 0:
    stock = money // a[i]
    money = money % a[i]
  elif delta_a[i] > 0 and 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)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
m = 1000
k = 0
flag = True
p = max(a)

if a[0] == p:
    print(1000)
    exit()

for i in range(n):
    if flag == True and a[i] < p:
        k += m // a[i]
        m = m % a[i]
        flag = False
        p = a[i]
    elif flag == False and a[i] > p:
        m += k * a[i]
        k = 0
        flag = True
        p = a[i]
print(m)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(x) for x in input().split()]

#シングル化
a2=[a[0]]
for i in range(1,len(a)):
    if a[i-1]!=a[i]:
        a2.append(a[i])

c=1000
s=0
mn=201
mx=99
for i in range(len(a2)):
    #次の日の方が小さい場合キープ
    if mn>a2[i]:
        #キープ
        mn=a2[i]
    else:
        #買う
        x=0
        while 1:
            x+=1
            if c<x*mn:
                s=x-1
                c-=s*mn
                mn=201
                break
    #次の方が大きい場合キープ
    if mx<a2[i]:
        #キープ
        mx=a2[i]
    else:
        #売る
        c+=mx*s
        s=0
        mx=99

#最後は換金
c+=mx*s
print(c)

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
a=list(map(int,input().split()))
money=1000
kabu=0
flg=0
first=True
if a[1]-a[0]>=0:
    flg="+"
else:
    flg="-"
x=a[1]

if len(a)==2:
    if a[1]>a[0]:
        kabu+=money//a[0]
        money-=a[0]*(money//a[0])
        money+=kabu*a[1]
    print(money)
    sys.exit()

for i , y in enumerate(a[2:],2):
    if flg=="+"  and y-x>=0:
        x=y
    elif flg=="-" and y-x<=0:
        x=y
    elif flg=="+" and y-x<0:
        x=y
        if first:
            kabu+=money//a[0]
            money-=a[0]*(money//a[0])
            first=False
        flg="-"
        money+=kabu*a[i-1]
        kabu=0
    elif flg=="-" and y-x>0:
        x=y
        if first:
            first=False
        flg="+"
        kabu+=money//a[i-1]
        money-=a[i-1]*(money//a[i-1])
    # print(flg,money,kabu)

if kabu!=0:
    if flg=="+":
        money+=kabu*a[-1]
    elif flg=="-":
        X=a[-1]
        for Y in a.reverse()[1:]:
            if X<=Y:
                X=Y
            else:
                money+=kabu*Y
                break
print(money)

Submission status: Wrong Answer

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

money = 1000
min_price = A[0]
max_price =A[0]
previous_tendency = "none"
current_tendency = "none"
count = 0

for n in range(1,len(A)-1):
    if A[n] < A[n+1]:
        max_price = A[n]
        if previous_tendency != "up":
            min_price = A[n]   
        current_tendency = "up"
        
    elif A[n] > A[n+1]:
        min_price = A[n]
        if previous_tendency != "down":
            max_price = A[n]
        current_tendency = "down"
    else:
        current_tendency = "none"
        
    if previous_tendency != "down" and current_tendency != "up":
        #print(n,"chance",max(A[count:n+1]),min(A[count:n+1]))
        money += (money//min(A[count:n+1]))*(max(A[count:n+1])-min(A[count:n+1]))
        #print(money)
        count = n
    #print(A[n],max_price,min_price,previous_tendency,current_tendency)
    previous_tendency = current_tendency
print(money)

Submission status: Wrong Answer

Solution code:
def solve():
    N = int(input())
    A_org = list(map(int,input().split()))
    A = [A_org[0]]
    isPosPrev = False
    for i in range(N-1):
        if A_org[i] == A_org[i+1]:
            continue

        isPosNow = True if A_org[i] < A_org[i+1] else False

        if i == 0:
            isPosPrev = isPosNow

        if isPosNow != isPosPrev:
            A.append(A_org[i])
        
        isPosPrev = isPosNow
    else:
        A.append(A_org[-1])

    A.append(-1)

    N = len(A) - 1
    for money_cand in range(10**5,1000, -1):
        money = money_cand
        stock = 0
        for i in range(N-1, -1, -1):
            if A[i] > A[i+1]:
                stock += money // A[i]
                money = money % A[i]
            elif A[i] < A[i+1]:
                money += stock * A[i]
                stock = 0
        
        else:
            money += stock * A[i]
            if money == 1000:
                print(money_cand)
                return
    
    print("1000")

if __name__ == '__main__':
    solve()

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:
        money += a[i] * stock
        break

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

    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]:
        num = money // a[i]
        if num != 0:
            stock += num
            money -= stock * a[i]

print(money)

Submission status: Wrong Answer

Solution code:
# coding: utf-8


N = int(input())
List = list(map(int, input().split()))
SUMList=[]

F=List[0]
check=0
for k in range(N):
    if List[k]<=F:
        check+=1
if check==N:
    print(1000)
    quit()


for i in range(N):
    List[i]
    cnt=0
    M=1000
    for j in range(i,N):
        if cnt==0:
            KABU=M//List[j]
            M=M%List[j]
            MAE=List[j]
        elif List[j]>MAE:
            M=M+(KABU*List[j])
            MAE=List[j]
            KABU=0
            cnt=0
        elif List[j]<MAE and (j+1)!=N:
            KABU=M//List[j]
            M=M%List[j]
            MAE=List[j]
        else:
            pass
        cnt+=1
        
    SUMList.append(M)
    
print(max(SUMList))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
syoji = 1000
kabu = 0
kai = 0
if N ==1:
  print(syoji)
  exit()

for i in range(N):
  if i<N-1 and kabu == 0 and A[i] < A[i+1]:
    for num in range (100000):
      if syoji < num*A[i]:
        kabu = num-1
        syoji = syoji - (num-1)*A[i]
        kai = A[i]
        break
  elif kabu > 0 and kai < A[i]:
    syoji = syoji + kabu*A[i]
    kabu = 0 

        
print(syoji)

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


if __name__ == "__main__":
    main()

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 = [157, 193, 193, 193, 191]

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

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

        if (i - 1 >= 0) and (i + 1 < n):
            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]})

    money = 1000
    num = 0

    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
            num = 0

    print(money)

arr = prepare(N, ARR)
calculate(arr)

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]:
        pass
    else:
        m=m + s * a[i]
        s=0
print(m)

Submission status: Wrong Answer

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

if a[0] < a[1]:
    botom.append(0)
if a[n-1] >= a[n-2]:
    peak.append(n-1)
for i in range(1, n-1):
    if a[i] >= a[i-1] and a[i] > a[i+1]:
        peak.append(i)
    if a[i] <= a[i-1] and a[i] < a[i+1]:
        botom.append(i)

for i in range(n):
    if i in botom:
        kabu = money//a[i]
        money %= a[i]
    if i in peak:
        money += kabu*a[i]
        kabu = 0

print(money)

Submission status: Wrong Answer

Solution code:
m = int(1000)
tmp = input()
a = list(map(int,input().split()))
s = 0
n = 0
for i in range(len(a)):
    if int(a[s]) < int(a[i]):
        m += (a[i] - a[s]) * (m // a[s])
        s = i
    else:
        continue
print(int(m))

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:
#!/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] >= 0:
        return dp[idx][stock]

    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()))
a.insert(0, a[0])
a.append(a[-1])
INF = 10 ** 9 + 7

money = 1000
mi = INF
ma = 0
for i in range(1, n + 1):
    mi = min(mi, a[i])
    ma = max(ma, a[i])
    if a[i - 1] <= a[i] >= a[i + 1]:
        stock = money // mi
        money %= mi
        money += stock * ma
        mi = a[i]
        ma = a[i]

print(money)

Submission status: Wrong Answer

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

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

money = 1000
stock = 0

if 1 in cng:
    stock += money // A[1]
    money -= stock * A[1]

for i in range(2, N):
    # buy
    if cng[i+1] == 1:
        ds = money // A[i]
        dm = ds * A[i]
        stock += ds
        money -= dm
    # sell
    elif cng[i+1] == -1:
        ds = stock
        dm = ds * A[i]
        stock -= ds
        money += dm
        

if stock != 0:
    money += stock * A[N]

print(money)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split())) # list()でリスト化、それを変数に代入。
money = 1000
kabu = 0
ind = 0
max_value = 0
min_value = 0
for i in range(n):
    if i == n-1:
        money += kabu*a[i]
        kabu = 0
    else:
        b = a[i:]
        max_value = max(b)
        ind = b.index(max_value)
        min_value = min(b[:ind+1])

        if a[i] == min_value and a[i] < max_value:
            kau = money//a[i]
            kabu += kau
            money -= kau*a[i]

        elif a[i] > min_value or a[i] == max_value:
            money += kabu*a[i]
            kabu = 0


print(money)

Submission status: Wrong Answer

Solution code:
import math
a = input()
b = input().split(" ")
c = []
for i in b:
  c.append(i)
money = 1000
senet = 0
chk = 0
c.sort(reverse=True)
for i in range(int(a)):
  for j in range(int(a)):
    if j != int(a)-1:
      if b[j] >= b[j+1]:
        pass;
      else:
        chk = 1 
  if chk == 0:
    break;
  elif i == int(a)-1:
    money = money + (senet * int(b[i]))
  elif i == 0:
    senet += math.floor(money / int(b[i]))
    money = money-(math.floor(money / int(b[i]))*int(b[i]))
  elif int(b[i]) < int(b[i+1]):
    if i <= int(a)-3:
      if int(b[i+1]) < int(b[i+2]):
        pass;
      else:
        senet += math.floor(money / int(b[i]))
        money = money-(math.floor(money / int(b[i]))*int(b[i]))
    else:
      senet += math.floor(money / int(b[i]))
      money = money-(math.floor(money / int(b[i]))*int(b[i]))
  elif int(b[i]) > int(b[i+1]):
    money += senet * int(b[i])
    senet = 0 
  elif int(b[i]) == int(b[i+1]):
    pass;
print(money)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
s=0
m=1000
l=0
for i in range(1,n):
  if a[i-1]<a[i]:
    l=i
if l==0:
  print(1000)
  exit()
if l<n-1:
  for i in range(l+1):
    if a[i]<a[i+1]:
      s+=m//a[i]
      m-=a[i]*(m//a[i])
    if a[i]>a[i+1]:
      m+=s*a[i]
      m=0
else:
  for i in range(l):
    if a[i]<a[i+1]:
      s+=m//a[i]
      m-=a[i]*(m//a[i])
    if a[i]>a[i+1]:
      m+=s*a[i]
      s=0
  m+=s*a[l]
print(m)

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

m += kabu * a[-1]

print(m)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
D = [A[i]-A[i-1] for i in range(1, n)] + [-1]
m = 1000
left = 0
while left<n:
    for right in range(left, n):
        if D[right]<0 and left<right:
            m += max((A[right]-A[left]), 0)*(m//A[left])
            left = right+1
print(m)

Submission status: Wrong Answer

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

    money = 1000
    stock = 0

    for i in range(1, N):
        if A[i-1] < A[i]:
            stock += money // A[i-1]
            money -= A[i-1] * (money // A[i-1])
            # print('buy  - stock: {}, money: {}'.format(stock, money))

        elif A[i-1] > A[i]:
            money += stock * A[i-1]
            stock = 0
            # print('sell - stock: {}, money: {}'.format(stock, money))

    if A[N-2] < A[N-1]:
        money += stock * A[N-1]
        stock = 0
        # print('sell - stock: {}, money: {}'.format(stock, money))

    print(money)


##########
if __name__ == "__main__":
    d()

Submission status: Wrong Answer

Solution code:
n = int(input(''))
alist = list(map(int,input('').split()))
money=1000
stock=0

for d in range(n-1):
    if stock ==0:
        if alist[d+1] > alist[d]:
            # 明日上がるなら買い
            stock+=int(money/alist[d])
            money-=stock*alist[d]
        else:
            # 明日下がる場合は何もしない
            pass
    else:
        if alist[d+1] > alist[d]:
            # 明日上がるなら全部売ってから買い
            money+=stock*alist[d]
            stock+=int(money/alist[d])
            money-=stock*alist[d]
        else:
            # 明日下がる場合で株を持っていたら売り
            money+=stock*alist[d]
            stock=0

money+=stock*alist[n-1]
stock=0
print(money)

Submission status: Wrong Answer

Solution code:
import numpy as np
n=int(input())
a = list(map(int, input().split()))
m = 1000
kabu = 0
for i in range(n-1):
  if a[i] < a[ i +1 ]:
    kabu = int((m - (m % a[i])) / a[i])
    m = m % a[i]
  elif a[i] > a[ i +1 ]:
    m = m + (a[i] * kabu)
    kabu = 0
if kabu > 0:
  m = m + kabu * a[-1]
print(m)

Submission status: Wrong Answer

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

    money = 1000
    stock = 0

    for i in range(1, N):
        print(A[i-1])
        if A[i-1] < A[i]:
            stock += money // A[i-1]
            money -= A[i-1] * (money // A[i-1])
            # print('buy  - stock: {}, money: {}'.format(stock, money))

        elif A[i-1] > A[i]:
            money += stock * A[i-1]
            stock = 0
            # print('sell - stock: {}, money: {}'.format(stock, money))

    if A[N-2] < A[N-1]:
        money += stock * A[N-1]
        stock = 0
        # print('sell - stock: {}, money: {}'.format(stock, money))

    print(money)


##########
if __name__ == "__main__":
    d()

Submission status: Wrong Answer

Solution code:
n=int(input())
#n,k=map(int,input().split())
v=list(map(int,input().split()))
l=list()
for i in v:
  if i not in l:
    l.append(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]
        p=z+r
    print(p)
  else:
    print(p)

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
        # これからずっと値段が変わらない場合は全部売ってあと放置
        possesion += num_stock * a_list[-1]
        print(possesion)
        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 = [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] and current == 0:
            stocks = value//A[i]
            value = value - stocks*A[i]
            current = 1
        if A[i]==max(A[i:]) and current ==1:
            value = value + stocks*A[i]
            stocks = 0
            current = 0
        elif A[i] > A[i+1] and current == 1:
            value = value + stocks*A[i]
            stocks = 0
            current = 0
    if current==1:
        value = value + stocks*A[N-1]
    print(value)