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:
import sys
import math
sys.setrecursionlimit(int(1e6))

money = 1000
stump = 0
n = list(map(int, input().split()))[0]
A = list(map(int, input().split()))
#print('n = ', n)
#print('A = ', A)

btm = A[0]
top = A[0]
for i in range(1, len(A)):
  #print('i = ', i)
  a_i = A[i]
  if (money>0):
    # buy
    if a_i < btm:
      btm = a_i
    else:
      p = money // btm
      stump = stump + p
      money = money - (p*btm)
      top = a_i
      btm = a_i
      #print('[buy] stump, money', stump, money)
  else:
    # sell
    if a_i > top:
      top = a_i
    else:
      money = money + (top*stump)
      stump = 0
      top = a_i
      btm = a_i
      #print('[sell] stump, money', stump, money)

if (stump>0):
  money = money + (top*stump)
  #print('[sell] stump, money', stump, money)

print(money)

Submission status: Wrong Answer

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

money = 1000
stock = 0
price = float("INF")
for i in range(N-1):
    if A[i] < A[i+1]:
        stock += money // A[i]
        money -= A[i] * stock
        price = A[i]

    if price < A[i] and stock != 0:
        money += stock * A[i]
        stock = 0
        price = float("INF")

if price < A[N-1] and stock != 0:
    money += stock * A[N-1]
    stock = 0
    price = float("INF")
    
print(money)

Submission status: Wrong Answer

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

flag=0
b=[]
c=[]
for i in range(n-1):
    if a[i]<a[i+1]:
        if flag>0:
            pass
        else:
            flag=1
            b.append(a[i])
    else:
        if flag<=0:
            pass
        else:
            flag=-1
            c.append(a[i+1])
    #print(a[i])
    
if flag==1:
    c.append(a[n-1])
    
            
if c==[]:
    print(1000)
else:
    money=1000
    kabu=0
    for i in range(len(b)):
        kabu=money//b[i]
        money=money-kabu*b[i]+kabu*c[i]
        kabu=0
    print(money)

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()))
X = [A[0]]
for i in range(1, N):
  if A[i] != A[i-1]:
    X.append(A[i])
B, C = [], []
n = len(X)
if n==1:
  print(1000)
else:
  status = 0
  result = 1000
  now_m = 1000
  k = 0
  if X[0]>X[1]:
    B.append(0)
  else:
    C.append(0)
  for i in range(1, n-1):
    if X[i-1]<X[i] and X[i]>X[i+1]:
      B.append(i)
  for i in range(1, n-1):
    if X[i-1]>X[i] and X[i]<X[i+1]:
      C.append(i)
  if X[n-2]<X[n-1]:
    B.append(n-1)
  else:
    C.append(n-1)
  S = set(B+C)
  for s in S:
    if status==0:
        k = now_m//X[s]
        now_m -= k*X[s]
        status = 1
    else:
        now_m += k*X[s]
        result = max(result, now_m)
        k = 0
        status = 0
  print(result)

Submission status: Wrong Answer

Solution code:
N = int(input())
A_list = list(map(int, input().split()))
mymoney = 1000
myValue = A_list[0]
nextpos = 1
myflag = 0  #0: buy,  1: sell
while nextpos < N:
    if myflag == 0:
        if A_list[nextpos] > myValue:
            kabu_num = mymoney // myValue
            mymoney -= kabu_num * myValue
            mymoney += kabu_num * A_list[nextpos]
            myflag = 1
            myValue = A_list[nextpos] 
    if myflag == 1:
        if A_list[nextpos] < myValue:
            myValue = A_list[nextpos]
            myflag = 0
    nextpos += 1
    #print(nextpos, mymoney, myValue)
print(mymoney)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
money = 1000
kabu = 0
temp = 200
for i in range(n):
  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 
  temp = a[i]
print(max(money,1000))

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
for i in range(1,n):
  if check_list[i] == hoge:
    check_list[hoge_idx] = "stay"
  else:
    hoge = check_list[i]
    hoge_idx = i
down_price = a_list[0]
for i in range(n):
  if check_list[i] == "down":
    down_price = a_list[i]
  if 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:
n = int(input())
a = list(map(int, input().split()))

a = a + [0]
b = 1000
c = 0
for i in range(1, n):
    numb = a[i-1]
    numa = a[i]
    numaa = a[i+1]
    if numb < numa:
        c = b//numb
        b = b%numb
    if numa > numaa:
        b += c*numa
        c = 0

b += c*a[-1]
c = 0
print(b)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = [0]*n
c = [0]*n
cash = 1000
stock = 0
#1:底 2:頂点 0:どちらでもない

for i in range(1,n):
    if a[i-1]<a[i]:
        b[i]='+'
    elif a[i-1]>a[i]:
        b[i]='-'
    elif a[i-1]==a[i]:
        b[i]=b[i-1]

if b[1]=='+':
    c[0]=1
elif b[1]=='-':
    c[0]=2

for i in range(1,n-1):
    if b[i]=='+' and b[i+1]=='-':
        c[i]=2
    elif b[i]=='-' and b[i+1]=='+':
        c[i]=1

if b[n-1]=='+':
    c[n-1]=2
elif b[n-1]=='-':
    c[n-1]=1
last = n
ch = 0
for i in range(n):
    if c[n-1-i]==1:
        ch = 1
    elif c[n-1-i]==2 and ch==0:
        break
    elif c[n-1-i]==2 and ch==1:
        last = n-i
        break
    if ch == 1 and i==0:
        last=0
        break

for i in range(last):
    if c[i]==1:
        stock += cash//a[i]
        cash -= cash//a[i]*a[i]
    if c[i]==2:
        cash += stock*a[i]
        stock =0
print(cash)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#n,k=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))
en=1000
kab=0
yamaf=False
tanif=False
for i in range(len(a)-1):
  if a[i]>a[i+1] and kab>0:
    en+=kab*a[i]
  
  if a[i]<a[i+1]:
    j=i
    kab=en//a[i]
    en=en-kab*a[i]
en+=kab*a[-1]
    
print(en)

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
    print(money,num)
if a[-1]>a[-2]:
    money+=a[-1]*num
elif a[-1]<=a[-2]:
    money=money
print(money)

Submission status: Wrong Answer

Solution code:
def solve():
    N = int(input())
    A = list(map(int,input().split()))
    A.append(-1)

    for money_cand in range(10**4,1000-1, -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:
#D
N = int(input())
A = list(map(int,input().split()))

price=1000 #現金
stock=0 #株数
for n in range(N-1):
    next_ = n+1
    
    if A[n] < A[next_]: #買い
        stock = price//A[n]
        price = price - A[n]*stock
        
    elif A[n] > A[next_]: #売り
        price = price + A[n]*stock
        stock = 0
        
price = price + A[-1]*stock
stock = 0
print(price)

Submission status: Wrong Answer

Solution code:

#!/usr/bin/python
# -*- coding: utf-8 -*-

import numpy as np

def int_mtx(N):
    x = []
    for _ in range(N):
        x.append(list(input()))
    return np.array(x)

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

money = 1000
stock = 0

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

if stock > 0:
    money = money + stock*A[N-1]
print(money)

Submission status: Wrong Answer

Solution code:
N = int(input())
As = list(map(lambda x: int(x), input().split(" ")))

money = 1000
stock = 0
left_money = money

# 買って個数または残金が多くなるか売って残金が多くなるか
for a in As:
    if money < left_money + a * stock:
        money = left_money + a * stock
        left_money = money
        stock = 0
    elif stock <= money // a:
        if stock == money // a:
            if left_money < money - stock * a:
                left_money = money - stock * a
        else:
            stock = money // a
            left_money = money - stock * a

print(money)

Submission status: Wrong Answer

Solution code:
import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]

N = ri()
A = ri_()
A.append(-1)
sell = set([])
buy = set([])
tmp = A[0]
f = 0
bf = False
for i in range(1, N + 1):
    if tmp < A[i]:
        if f == 0:
            f = 1
            buy.add(0)
        if f == 1:
            f = 1
        else:
            buy.add(i - 1)
            f = 1
    elif tmp > A[i]:
        if f == 0 or f == 2:
            f = 2
        else:
            sell.add(i - 1)
            f = 2
    tmp = A[i]
m = 1000
k = 0
tmp = 0
for L in sell:
    for i in range(L):
        if i in buy:
            k = k + m // A[i]
            m = m % A[i]
        elif i in sell:
            m = m + k * A[i]
            k = 0
    tmp = max(tmp, m + k * A[L])
print(tmp)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
*A,=map(int,input().split())
M=max(A)

now=1000
amari=0
stock=0
i=0
while i<N-1:
    if A[i]<A[i+1]:
        if stock<now//A[i]:
            stock=now//A[i]
            amari=now%A[i]
    elif A[i]>A[i+1]:
        now=max(A[i]*stock+amari,now)
    i+=1

now=max(amari+stock*A[i],now)
print(now)

Submission status: Wrong Answer

Solution code:
days = int(input())
yen = 1000
prices = list(map(int, input().split()))
stocks = 0

for i in range(0, days-1):
  if prices[i] < prices[i+1]:
    stocks = yen // prices[i]
    yen %= prices[i]
  elif prices[i] > prices[i+1]:
    yen += stocks*prices[i]
    stocks = 0

yen += stocks*prices[days-1]

print(yen)

Submission status: Wrong Answer

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

M = 1000
X = 0

for i in range(N-1):
    if A[i] < A[i+1]:
        X = int(M/A[i])
        M = M - X * A[i]
    
    elif A[i] > A[i+1]:
        M = M + A[i] * X
        X = 0

if X > 0:
    M = M + X * A[N-1]


print(M,X)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = tuple(dict.fromkeys(map(int, input().split())))
pattern = []
for i in range(2 ** len(A)):
  money, stock = 1000, 0
  for j in range(len(A)):
    if i >> j & 1:
      if stock:
        money += stock * A[j]#?
        stock = 0
      else:
        stock = money // A[j]
        money %= A[j]
  pattern.append(money)
print(max(pattern))

Submission status: Wrong Answer

Solution code:

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

MAX = 10 ** 6 + 10
dp = [-1] * MAX
dp[0] = 1000
for i in range(N):
    for j in range(1, MAX):
        dp[j] = max(dp[j], dp[j - 1] - X[i])

    for j in reversed(range(MAX - 1)):
        if dp[j + 1] >= 0:
            dp[j] = max(dp[j], dp[j + 1] + X[i])

print(max(dp))

Submission status: Wrong Answer

Solution code:
# coding: utf-8


def solve(*args: str) -> str:
    n = int(args[0])
    A = list(map(int, args[1].split()))
    budget = 1000
    stock = 0
    temp = 0

    for i in range(n-1):
        if A[i] < A[i+1] and A[i] <= temp+budget:
            budget += temp
            temp = 0
            stock = budget//A[i]
            budget %= A[i]
        elif A[i+1] < A[i]:
            temp = max(temp, A[i]*stock)

    return str(A[-1]*stock+budget+temp)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Submission status: Wrong Answer

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

stair = []
startDate = 0
firstFlag = True
for i in range(1, N):
    if (A[i] == A[i - 1]):
        stair.append(0)
        continue
    if (A[i] < A[i - 1]):
        stair.append(-1)
    else:
        if (firstFlag):
            firstFlag = False
            startDate = i - 1
        stair.append(1)

upflag = False
base = 1000
ticket = 0
for i in range(startDate, N - 1):
    if (stair[i] == 0):
        continue
    if (upflag):
        if (stair[i] == -1):
            base += ticket * A[i]
            upflag = False
    else:
        if (stair[i] == 1):
            ticket = int(base / A[i])
            base -= ticket * A[i]
            upflag = True

if (ticket != 0):
    base += ticket * A[N - 1]

print(base)

Submission status: Wrong Answer

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

mo=1000
ch=0
tu=0
for i in range(1,n):
  if a[i-1]<a[i]:
    ch+=1
  if a[i-1]>a[i] and ch>0:
    y=min(a[tu:i])
    ka=mo//y
    mo=mo-ka*y
    mo=mo+a[i-1]*ka
    tu=i
    ch=0
  if i==n-1:
    if a[i-1]<a[i]:
      y=a[i-1]
      ka=mo//y
      mo=mo-ka*y
      mo=mo+a[i]*ka
  
    
print(mo)

Submission status: Wrong Answer

Solution code:

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

MAX = 10 ** 5 + 10
dp = [-1] * MAX
dp[0] = 1000
for i in range(N):
    for j in range(1, MAX):
        dp[j] = max(dp[j], dp[j - 1] - X[i])

    for j in reversed(range(MAX - 1)):
        if dp[j + 1] >= 0:
            dp[j] = max(dp[j], dp[j + 1] + X[i])

print(max(dp))

Submission status: Wrong Answer

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N = I()
A = LI()
money,stock = 1000,0
temp,temp2 = A[0],0
for i in range(1,N):
    if temp<A[i]:
        stock = money//A[i-1]
        money -= A[i-1]*stock
    if temp>A[i]:
        temp2 = temp
    if temp2>A[i]:
        if stock:
            money += A[i-1]*stock
            stock = 0
        temp2 = 0
    if i==N-1:
        if stock:
            money += A[i]*stock
    temp = A[i]
print(money)

Submission status: Wrong Answer

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

        kabu=int(kane/A[a])
        kane=kane-kabu*A[a]
    elif A[a]>A[a+1] and kabu>1:
        kane=kane+kabu*A[a]
        kabu=0
    
if kabu>0:
    kane+=kabu*A[-1]
print(kane)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = [int(v) for v in input().split()]
    m = 1000
    k = 0

    sokosagashi = True
    a0 = a[0]
    ah = a0
    for d,ai in enumerate(a[1:]):
        if ai==a0:
            continue

        if ai>a0:
            if sokosagashi:
                m += k * ah
                k = 0
                sokosagashi = False
            # すべて株に変える
            k = m // a0
            m -= k * a0
            a0 = ai
            ah = ai
        elif ai<a0:
            sokosagashi = True
            a0 = ai
    
    if k>0:
        m += k * ah
    print(m)

main()

Submission status: Wrong Answer

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

Y = 1000
stack = []
for i in range(N):
  if not stack:
    stack.append(A[i])
  elif A[i] < stack[-1]:
    stack[-1] = A[i]
  elif A[i] > stack[-1]:
    div, mod = divmod(Y, stack.pop())
    Y = A[i] * div + mod
print(Y)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
a = Counter(A)
cnt = 0
money = 1000
before = 0
for i in range(n):
    a[A[i]] -= 1
    if a[A[i]] == 0: a.pop(A[i])

    if cnt > 0 and before < A[i]:
        money += cnt * A[i]
        cnt = 0
        before = A[i]
    elif before != A[i]:
        flag = False
        for x,y in a.items():
            if x > A[i]:
                flag = True
                break
        if flag:
            before = A[i]
            cnt += money//A[i]
            money %= A[i]
        else:
            before = A[i]
            money += cnt * A[i]

print(money)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = [0]*n
c = [0]*n
cash = 1000
stock = 0
#1:底 2:頂点 0:どちらでもない

for i in range(1,n):
    if a[i-1]<a[i]:
        b[i]='+'
    elif a[i-1]>a[i]:
        b[i]='-'
    elif a[i-1]==a[i]:
        b[i]=b[i-1]

if b[1]=='+':
    c[0]=1
elif b[1]=='-':
    c[0]=2

for i in range(1,n-1):
    if b[i]=='+' and b[i+1]=='-':
        c[i]=2
    elif b[i]=='-' and b[i+1]=='+':
        c[i]=1

if b[n-1]=='+':
    c[n-1]=2
elif b[n-1]=='-':
    c[n-1]=1
last = n
ch = 0
for i in range(n):
    if c[n-1-i]==1:
        ch = 1
    elif c[n-1-i]==2 and ch==0:
        break
    elif c[n-1-i]==2 and ch==1:
        last = n-i
        break

for i in range(last):
    if c[i]==1:
        stock += cash//a[i]
        cash -= cash//a[i]*a[i]
    if c[i]==2:
        cash += stock*a[i]
        stock =0
print(cash)

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:
    if senet != 0:
      money = money + (senet * int(b[i]))
    else:
      pass;
  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]):
    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 c[0] > b[i]:
      money += senet * int(b[i])
      senet = 0 
    else:
      pass
  elif int(b[i]) == int(b[i+1]):
    pass;
print(money)

Submission status: Wrong Answer

Solution code:
import numpy as np


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

    A = np.int32(A)
    D = np.diff(A)
    if np.all(D <= 0):
        return 1000
    if np.all(D >= 0):
        stock, money = divmod(1000, A[0])
        money = stock * A[-1] + money
        return money

    money = 1000
    s = 0
    while s < N - 1:
        t = s + 1
        if A[t] >= A[s]:
            while t < N and A[t] >= A[t - 1]:
                t += 1
            # print('++:', A[s:t], s, t)
            stock, money = divmod(money, A[s])
            money = stock * A[t - 1] + money
            s = t
        else:
            while t < N and A[t] < A[t - 1]:
                t += 1
            # print('--:', A[s:t])
            s = t
    
    return money


print(solve())

Submission status: Wrong Answer

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

for i in range(N-1):
    if (A[i] < A[i+1]):
        kabu += total//A[i]
        total -= kabu*A[i]
    elif(A[i]==A[i+1]):
        pass
    elif(A[i] > A[i+1]):
        total += (kabu*A[i])
        kabu = 0
    #print(kabu,total)

#最後
i += 1
total += (kabu * A[i])
kabu = 0
print(total)

Submission status: Wrong Answer

Solution code:
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math
from collections import deque
import itertools
import heapq
#import bisect
from fractions import Fraction
import copy
from functools import lru_cache
from collections import defaultdict
import pprint

#oo=list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
# ko=list("abcdefghijklmnopqrstuvwxyz")

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)

def soinsubunkai(n):
    a = []
    i = 1
    while i*i <= n:
        if n % i == 0 and i!=1:
            a.append(i)
            n=n//i

        if n% i !=0 or i==1:
            i += 1
    nokori=[n]
    return a + nokori

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

def main():
    #l,r,d=map(int,input().split())
    n=int(input())
    a=list(map(int,input().split()))
    now=1000
    nokoritemp=1000
    kabu=0
    bos=[0 for i in range(n)] #0=buy 1=sell 2=none
    for i in range(n-1):
        if a[i]>a[i+1]:
            bos[i]=1
    bos[n - 1] = 1
    for i in range(n-1):
        if bos[i+1]==1 and bos[i]==1:
            bos[i]=2



    for i in range(n):
        if bos[i]==1:
            now=now+kabu*a[i]
            kabu=0
        elif bos[i]==0:
            urukabu=0
            kaukabu=0
            for j in range(kabu+1):
                kaukabu=(a[i]*j+now)//a[i]
                temp=j*a[i]+now-((a[i]*j+now)//a[i])*a[i]
                if now>=temp:
                    now=temp
                    urukabu=j
            kabu=kabu+kaukabu-urukabu
    print(now)



if __name__ == "__main__":

    main()

Submission status: Wrong Answer

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

C = 1000
S = 0

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

print(C)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = [int(v) for v in input().split()]
    m = 1000
    k = 0

    sokosagashi = True
    a0 = a[0]
    ah = a0
    for d,ai in enumerate(a[1:]):
        if ai==a0:
            continue

        if ai>a0:
            if sokosagashi:
                m += k * ah
                k = 0
                sokosagashi = False
            # すべて株に変える
            k = m // a0
            m -= k * a0
            a0 = ai
            ah = ai
        elif ai<a0:
            sokosagashi = True
            a0 = ai
    
    if k>0:
        m += k * ai
    print(m)

main()

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
a=0
c=1000
m=0
for i in range(N-1):
  if A[i]<A[i+1]:
    a,c=divmod(c,A[i])
  if A[i]>A[i+1]:
    c+=a*A[i]
    a=0

print(a*A[-1]+c)

Submission status: Wrong Answer

Solution code:
def resolve():
    D = int(input())
    A = [int(i) for i in input().split()]
    stock = 0
    N = 1000
    for i in range(D - 1):
        if A[i] < A[i + 1]:
            # 購入
            stock = N // A[i]
            N -= A[i] * stock
        elif stock > 0:
            # 売却
            N += stock * A[i]
            stock = 0
        else:
            continue
    if stock > 0:
        # 売却
        N += stock * A[-1]
        stock = 0
    print(N)

resolve()

Submission status: Wrong Answer

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

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

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

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

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

print(money)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
money=1000
num=0
if max(a)==a[0] or min(a)==a[-1]:
    print(1000)
else:
    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 = [int(a) for a in input().split()]

dp = [0]*(N+1)
L1 = [[0]*2 for _ in range(N+1)]
L2 = [[0]*2 for _ in range(N+1)]
L1[0][0] = 1000

for i in range(N):
    for j in range(i+1):
        if L1[i+1][0] < L1[j][0]+L1[j][1]*A[i]:
            L1[i+1][0] = L1[j][0]+L1[j][1]*A[i]
            L1[i+1][1] = 0
        if L1[i+1][0] < L2[j][0]+L2[j][1]*A[i]:
            L1[i+1][0] = L2[j][0]+L2[j][1]*A[i]
            L1[i+1][1] = 0
        if L2[i+1][1] < L1[j][1]+L1[j][0]//A[i]:
            L2[i+1][1] = L1[j][1]+L1[j][0]//A[i]
            L2[i+1][0] = L1[j][0]%A[i]
        if L2[i+1][1] < L2[j][1]+L2[j][0]//A[i]:
            L2[i+1][1] = L2[j][1]+L2[j][0]//A[i]
            L2[i+1][0] = L2[j][0]%A[i]
    dp[i+1] = max(dp[i], L1[i+1][0]+L1[i+1][1]*A[i], L2[i+1][0]+L2[i+1][1]*A[i])

print(dp[-1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
*A,=map(int,input().split())
M=max(A)

now=1000
amari=0
stock=0
i=0
while i<N-1:
    if A[i]<A[i+1]:
        if stock<now//A[i]:
            stock=now//A[i]
            amari=now%A[i]
    elif A[i]>A[i-1]:
        now=max(A[i]*stock+amari,now)
    i+=1

now=max(amari+stock*A[i],now)
print(now)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

genkin = 1000
kabu = 0

for i in range(N-1):
    if A[i] < A[i+1]:
        kabu = genkin // A[i]
        genkin = genkin % A[i]
    if A[i] > A[i+1]:
        genkin += kabu * A[i]
        kabu = 0
    # print(genkin, kabu)

print(genkin + kabu * A[N-1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
a = Counter(A)
cnt = 0
money = 1000
before = 0
for i in range(n-1):
    a[A[i]] -= 1
    if a[A[i]] == 0: a.pop(A[i])

    if cnt > 0 and before < A[i]:
        money += cnt * A[i]
        cnt = 0
        before = A[i]
    elif before != A[i]:
        flag = False
        for x,y in a.items():
            if x > A[i]:
                flag = True
                break
        if flag:
            before = A[i]
            cnt += money//A[i]
            money %= A[i]
if cnt > 0:
    money += cnt * A[-1]
print(money)