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:
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"
        elif trend == "D" and tempValue >= values[i]:
            tempValue = values[i]
        elif trend == "U" and tempValue <= values[i]:
            tempValue = values[i]

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()))
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:
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(1000 < a):
    print(a)
    exit()
  else:
    print("1000")

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])
    
    if A[0] > A[1]:
        A = A[1:]

    N = len(A)
    money = 1000
    for i in range(0,N,2):
        if i+1 >= N:
            break
        money = money // A[i] * A[i+1] +  money % A[i]
    
    print(money)
        
if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

money = 1000
mount = 0

f = -1
pre = a[0]
for i in range(1, len(a)):
    if f < 0:
        if a[i] <= pre:
            continue
        mount += money // pre
        money %= pre
        f *= -1
    else:
        if a[i] >= pre:
            continue
        money += mount * pre
        mount = 0
        f *= -1

    pre = a[i]

money += mount * a[-1]
print(money)

Submission status: Wrong Answer

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

import math
ans = 1000
base = 100
l = -1
r = -1
for i in range(N-1):
    if l == -1:
        l = i
    elif r == -1:
        if A[i] < A[l]:
            l = i
        else:
            r = i
            if A[i] >= A[i+1]:
                ans = math.floor((ans / A[l])) * A[r] + ans % A[l]
                l = -1
                r = -1
    else:
        if A[i] > A[r]:
            r = i
        else:
            ans = math.floor((ans / A[l])) * A[r] + ans % A[l]
            l = -1
            r = -1
if l != -1 and A[N-1] > A[l]:
    r = N-1
    ans = math.floor((ans / A[l])) * A[r] + ans % A[l]

print(ans)

Submission status: Wrong Answer

Solution code:
#関数リスト
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n = I()
mylist = LI()
buy = [0] * n

if n == 2:
    if mylist[0] >= mylist[1]:
        print(1000)
    else:
        stock = 1000 // mylist[0]
        print(1000+stock*(mylist[1] - mylist[0]))
    sys.exit()

katamuki = 0
for i in range(n-1):
    if katamuki == 0:
        if mylist[i+1] > mylist[i]:
            buy[0] = "buy"
        elif mylist[i+1] < mylist[i]:
            katamuki = -1
    if katamuki == -1 and mylist[i+1] > mylist[i]:
        buy[i] = "buy"

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(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 = [int(i) for i in input().split()]

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

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

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 ls[j-1]==1:
                    ls[j-1]=0
                l = j
            elif a[l]>a[j]:
                ls[j] = -1
                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]
        for k in range(len(ls)):
            if ls[k]==1:
                m = m+cnt*a[k]
                cnt = 0
            elif ls[k]==-1:
                if 1 not in ls[k+1:]:
                    continue
                cnt = m//a[k]
                m = m-cnt * a[k]
        if m>ans:
            ans = m
    print(ans)
                

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())
lst1 = list(map(int,readline().split()))
ct = 1000
stock = 0
#次の日に上がるか下がるか
lst2 = [0]*n
for i in range(n-1):
    if lst1[i] < lst1[i+1]:
        lst2[i] = 1
    elif lst1[i] > lst1[i+1]:
        lst2[i] = -1
for i in range(n):
    if lst2[i] == 1:
        stock = ct//lst1[i]
        ct %= lst1[i]
    elif lst2[i] == -1:
        ct += stock*lst1[i]
        stock = 0


print(ct + stock*lst1[-1])

Submission status: Wrong Answer

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

money = 1000
kabu = 0
toku = 0
min_val = 10000

for i in range(N):
    if (A[i] < min_val):
        min_val = A[i]

    if (A[i] > min_val):
        money += (money // min_val) * (A[i] - min_val)
        min_val = 10000

print(money)

Submission status: Wrong Answer

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



counter = 0
while True:
    if A[counter]<A[counter+1]:
        break
    counter +=1
    if counter >= N-2:
        print(1000)
        exit()
    
value = A[counter]
num = 1000//A[counter]
flag = 1
max_ = 1000
posess = 1000%A[counter]


for i in range(counter+1,N):
    ok = A[i]
    if flag:
        print(ok,value)
        if ok >= value:
            posess += num*ok
            max_ = max(max_,posess)
            num = 0
            flag = 0
            value = ok
    else:
        if ok < value :
            num = posess//ok
            posess %= ok
            flag = 1
            value = ok

            
print(max_)

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

value = list(map(int, input().split(' ')))

budget = 1000
             
buyDay = value.index(min(value))

sellDay = value.index(max(value))
             
if buyDay > sellDay:
  print(budget)
else:
  num = budget // value[buyDay]
  budget = budget - num * value[buyDay]
  print(budget + num * value[sellDay])

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(ans)
    print(max(ans))

if __name__ == '__main__':
    main()

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:
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

money = 1000
stock = 0
cnt = 0

while True:
    if A[cnt+1] > A[cnt]:
        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()))

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]

if 'b' not in bs:
    bs[0] = 'b'
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(zan)

Submission status: Wrong Answer

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

stack = 0
ans = 1000

Flag = False
i,j  = 0, 0

while i < n-1:
    if a[i] < a[i+1]:
        stack = ans // a[i]
        ans -= stack*a[i]
        j = i
        while j < n-1:
            if a[j] > a[j+1]:
                ans += stack*a[j]
                stack = 0
                i = j
                Flag = True
                break
            j += 1

    if Flag:
        Flag = False
        continue

    i += 1

if a[-2] < a[-1]:
    ans += stack*a[-1]

print(ans)

Submission status: Wrong Answer

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

cash = 1000
stocks = 0

buy = []
sell = []

trend = 'down'

for i in range(n-1):
    if trend == 'down':

        if A[i] >= A[i+1]:
            continue
        else:
            trend = 'up'
            buy.append(i)
            if i == n-2:
                sell.append(i+1)
    # 'up'
    else:
        if A[i] <= A[i+1]:
            continue
        else:
            trend = 'down'
            sell.append(i)

while len(buy) and len(sell):
    b = buy.pop(0)
    count = cash // A[b]
    cash -= A[b] * count
    stocks += count

    s = sell.pop(0)
    cash += A[s] * stocks
    stocks = 0

print(cash)

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"
        elif trend == "D" and tempValue > values[i]:
            tempValue = values[i]
        elif trend == "U" and tempValue < values[i]:
            tempValue = values[i]

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()))
b = [0]*n
for i in range(n-1):
    if(a[i] < a[i+1]):
        if(b[i-1] < 1):
            b[i] = 1
        else:
            b[i] = 2
    if(a[i] > a[i+1]):
        if(b[i-1] > -1):
            b[i] = -1
        else:
            b[i] = -2
b[-1] = -1
#print(b)
h = [1000,0]
for i in range(n):
    if(b[i] == 1):
        h[1] = h[0]//a[i]
        h[0] %= a[i]
    elif(b[i] == -1):
        h[0] += h[1]*a[i]
        h[1] *= 0
    #print(h)
print(h[0])

Submission status: Wrong Answer

Solution code:
import copy
N = int(input())
A = list(map(int, input().split()))
B=[A[0]]
for i in range(1,N):
    if A[i-1]!=A[i]:
        B.append(A[i])

C = copy.deepcopy(B)
for i in range(len(B)-1):
    if  B[i]>B[i+1]:
        C[i]=0 
    else:
        break
C=[s for s in C if s != 0]
#print(C)
C.reverse()
for i in range(len(C)-1):
    if  C[i]<C[i+1]:
        C[i]=0 
    else:
        break
C=[s for s in C if s != 0]
C.reverse()
#print(C)
kane=1000
kabu=0
for i in range(len(C)-1):
    if C[i]<C[i+1]:
        kabu=kane//C[i]
        kane=kane-kabu*C[i]
    else:
        kane=kane+C[i]*kabu
kane=kane+kabu*C[len(C)-1]
print(kane)

Submission status: Wrong Answer

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

wallet = 1000
stock = 0

for i in range(N - 1):
    if A[i] < A[i + 1] and wallet > 0:  # 次値上がり and 金がある→買う
        action = wallet // A[i] 
        if wallet >= action * A[i]:
            stock += wallet // A[i]
            wallet -= stock * A[i]
    elif A[i] > A[i + 1] and stock > 0:  # 次値下がり and 株持っている→売り
        wallet += stock * A[i]
        stock = 0

# 最後残っていたら全部売る
wallet += stock * A[-1]

print(wallet)

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]
            #print("A",KABU,M)
        elif (j+1)==N:
            M=M+(KABU*List[j])
            MAE=List[j]
            KABU=0
            cnt=0
            #print("D",KABU,M)

        elif List[j]>MAE:
            M=M+(KABU*List[j])
            MAE=List[j]
            KABU=0
            cnt=0
            #print("B",KABU,M)
        elif List[j]<MAE and (j+1)!=N:
            KABU=KABU+(M//List[j])
            M=M%List[j]
            MAE=List[j]
            #print("C",KABU,M)
        else:
            #print("E",KABU,M)
            pass
        #print(KABU,M)
        cnt+=1
        #print(M)
        
    SUMList.append(M)
    #print("AAAAAAAAAAAAAA")
    
print(max(SUMList))

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'

if 'b' not in bs:
    bs[0] = 'b'

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

Submission status: Wrong Answer

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

stack = 0
ans = 1000

Flag = False
i,j  = 0, 0

while i < n-1:
    if a[i] < a[i+1]:
        stack = ans // a[i]
        ans -= stack*a[i]
        j = i
        while j < n-1:
            if a[j] > a[j+1]:
                ans += stack*a[j]
                stack = 0
                i = j
                Flag = True
                break
            j += 1

        if Flag:
            Flag = False
            continue

    i += 1

if a[-2] < a[-1]:
    ans += stack*a[-1]

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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(0,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()))
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 = [i for i in map(int, input().split())]
trace = [0 for i in range(N)]
buy = [0 for i in range(N)]
sell = [0 for i in range(N)]
buy[0]= -A[0]
for i in range(1,N):
    buy[i] = max(buy[i-1],sell[i-1]-A[i])
    sell[i] = max(sell[i-1],buy[i-1]+A[i])
flag=0
tmp = -1
for i in range(N-1,0,-1):
    if flag ==1 and i == 1:
        trace[tmpbuy] =1
    if flag == 1 and not buy[i-1] == tmp:
        trace[tmpbuy] = 1
        flag = 0
    if sell[i-1]<buy[i-1]+A[i]:
        trace[i] = 2
        tmp = buy[i-1]
    if buy[i-1]==tmp:
        flag = 1
        tmpbuy = i-1
    if flag ==1 and i == 1:
        trace[tmpbuy] =1
n=0
M = 1000
for i in range(N):
    if trace[i] == 1:
        n = int(M/A[i])
        M = M-n*A[i]
    if trace[i] == 2:
        M = M+n*A[i]
print(M)

Submission status: Wrong Answer

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

wallet = 1000
stock = 0

for i in range(N - 1):
    if A[i] < A[i + 1] and wallet > 0:  # 次値上がり and 金がある→買う
        action = wallet // A[i] 
        if wallet >= action * A[i]:
            stock += wallet // A[i]
            wallet -= stock * A[i]
    elif A[i] > A[i + 1] and stock > 0:  # 次値下がり and 株持っている→売り
        wallet += stock * A[i]
        stock = 0
    print(i, wallet, stock)

# 最後残っていたら全部売る
wallet += stock * A[-1]

print(wallet)

Submission status: Wrong Answer

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

for i in range(n-1):
    # すべて現金
    genkin_tmp = genkin + a[i] * kabu

    # すべて株
    kazu = genkin//a[i]
    kabu_tmp = genkin - kazu * a[i] + kazu * a[i+1]

    if genkin_tmp > kabu_tmp:
        genkin = genkin + kabu * a[i]
        kabu = 0
    elif genkin_tmp < kabu_tmp:
        genkin = genkin - kazu * a[i]
        kabu = kabu + kazu

print(genkin + kabu * a[-1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
mny = 1000
Kab = 0
base = 0
typ = 1 # 1なら買いモード、0なら売りモード
if n != 2:
    if A[0] < A[1]:
        kab = mny // A[0]
        mny = mny % A[0]
        typ -= 1
    for i in range(1, n-1):
        if A[base] < max(A[base:]):
            if typ == 1:
                if A[i-1] >= A[i] < A[i+1]:
                    kab = mny // A[i]
                    mny = mny % A[i]
                    typ -= 1
            else:
                if A[i-1] <= A[i] > A[i+1]:
                    mny += kab*A[i]
                    kab = 0
                    base = i
                    typ += 1
        else:
            break
    if typ == 0:
        mny += kab*A[n-1]
else:
    if A[0] < A[1]:
        kab = mny // A[0]
        mny = mny % A[0]
        mny += kab*A[1]
print(mny)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
LIST_A = list(map(int,input().split()))

flag = True
money = 1000
i = 0
distance = 0
upstair = False
while flag == True:
  
  #print("i:",i,"distance:",distance)
  if LIST_A[distance+1] - LIST_A[distance] >= 0:
    #print(LIST_A[1+distance])
    #print(LIST_A[distance])
    if LIST_A[distance+1] - LIST_A[distance] > 0:
      upstair = True
    else:
      upstair = "updown"
    distance += 1
    
  else:
    #print("down")
    if upstair == True or upstair == "updown" and money >= LIST_A[i]:
      money += (money//LIST_A[i])*(LIST_A[distance]-LIST_A[i])
      #print(money)
      upstair = False
    	
    i = distance+1
    distance += 1
    
  	
    
  if N <= distance+1:
    if upstair == True:
      #print("distance+1",distance+1)
      #print(money)
      money += (money//LIST_A[i])*(LIST_A[distance]-LIST_A[i])
    print(money)
    sys.exit()

Submission status: Wrong Answer

Solution code:
import numpy as np
from scipy import signal

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

f = True
while f:
  f = False
  for i in range(len(A)-1):
    if A[i] == A[i+1]:
      A.pop(i)
      f = True
      break
  if len(A) == 1:
    print(1000)
    exit()

B = np.array(A)
maxId = signal.argrelmax(B, mode='wrap')[0]
minId = signal.argrelmin(B, mode='wrap')[0]

money = 1000
kabu = 0
for i, b in enumerate(B):
  if i in maxId:
    money += kabu * b
    kabu = 0
  elif i in minId and max(maxId)>i:
    kabu += money // b
    money = money % b
print(money)

Submission status: Wrong Answer

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

kabu = 0
money = 1000

for day in range(N):
  if kabu > 0:
    if rate[day-1] < rate[day] or day == N-1:
      money = money + kabu*rate[day]
      kabu = 0
    else:
      None
  else:
    if day == N-1:
      None
    elif rate[day] < rate[day+1]:
      kabu = money // rate[day]
      money = money - kabu*rate[day]
      
print(money)

Submission status: Wrong Answer

Solution code:
a = int(input())
data = list(map(int, input().split()))
l =[]
money = 1000
stock = 0
data += [0]
for i in data:
  if i not in l:
    l += [i]

diff = []
dd = []
init = 0
for i in range(len(l) - 1):
  if l[i] > l[i + 1]:
    if init == i:
      continue
    if not diff:
      mini = min(l[init:i])
      diff += [l[i] - mini]
      init = i + 1
      dd += [[l[i], mini]]
    elif diff[-1] > l[i + 1] - l[i]:
      mini = min(l[init:i])
      diff += [l[i] - mini]
      init = i + 1
      dd += [[l[i], mini]]

if sum(diff) < 0:
  print('1000')
  exit(0)
for d in dd:
  stock = money // d[1]
  money -= stock * d[1]
  money += stock * d[0]
  stock = 0
print(money)

Submission status: Wrong Answer

Solution code:
def resolve():
    import numpy as np
    n = int(input())
    A = list(map(int, input().split()))
    C = 1000
    kabu = 0
    buy = []
    sell = []

    # for i in range(n - 1, 0, -1):
    #     if A[i] > A[i - 1]:
    #         sell.append(i)
    #         if i == 1:
    #             buy.append(0)
    #     elif A[i] < A[i - 1] and len(sell) != 0:
    #         buy.append(i)

    l = 0
    flag = 1
    for i in range(1, n):
        if A[i - 1] <= A[i] and flag:
            l = i - 1
            flag = 0
        elif flag == 0:
            k = C // A[l]
            C -= k * A[l]
            kabu += k

            C += kabu * A[i - 1]
            kabu = 0
            flag = 1

        # if i in buy:
        #     k = C // A[i]
        #     C -= k * A[i]
        #     kabu += k
        # elif i in sell:
        #     C += kabu * A[i]
        #     kabu = 0

#    print(l, kabu, C)
    if A[l] < A[-1]:
        k = C // A[l]
        C -= k * A[l]
        kabu += k
        C += kabu * A[-1]
    print(C)

resolve()