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
from collections import deque
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    N = readint()
    A = list(readnums())
    d = deque(A)
    d.appendleft(201)
    d.append(0)
    # ans = 1000 + (max(A) - min(A)) * (1000 // min(A))
    il = []
    for i in range(N):
        if d[i] <= d[i + 1] and d[i + 1] > d[i + 2]:
            il.append(i)
        elif d[i] >= d[i + 1] and d[i + 1] < d[i + 2]:
            il.append(i)

    if len(il) == 1:
        print(1000)
    else:
        b = 1000
        s = 0
        for i, v in enumerate(il):
            if not i % 2:
                s += b // A[v]
                b -= s * A[v]
            else:
                b += s * A[v]
                s = 0

        print(b)


if __name__ == "__main__":
    main()

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]
        stock += ds
        dm = ds * A[i]
        money -= dm
    # sell
    elif cng[i+1] == -1:
        money += stock * A[i]
        stock = 0

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

print(money)

Submission status: Wrong Answer

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

downTrend = True

prev = l[0]
for i in range(1, N):
    A = l[i]
    if downTrend == True:
        if A < prev:
            prev = A
        else:
            stock, cash = divmod(cash, prev)
            prev = A
            downTrend = False
    else:
        if A > prev:
            prev = A
        else:
            cash += stock * prev
            stock = 0
            downTrend = True
cash += stock * prev

print(cash)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(4100000)

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

dp = [[-1] * (1000000) for i in range(N + 1)]

def dfs(i, money, kabu_num):
    if dp[i][money] >= 0:
        return dp[i][money]

    if i == N:
        return money

    # 買う
    a = dfs(i + 1, money % A[i], money // A[i] + kabu_num)
    # 売る
    b = dfs(i + 1, money + A[i] * kabu_num, 0)
    # 何もしない
    c = dfs(i + 1, money, kabu_num)

    dp[i][money] = max([a, b, c])

    return dp[i][money]

print(dfs(0, 1000, 0))

Submission status: Wrong Answer

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

money = 1000
asset = 0

for i in range(n):
    if asset == 0:
        if a[i] == max(a[i:n]):
            pass
        else:
            asset = money // a[i]
            money = money - asset * a[i]
    else:
        if a[i] == min(a[i:n]) and i != n-1:
            pass
        else:
            money += asset * a[i]
            asset = 0
    # print("money", money)
    # print("asset", asset, "\n")

print(money)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
values = np.array(list(map(int, input().split())))

money = 1000
kabu = 0
last_value = 10000
for i in range(n-1):
    #print(last_value, kabu, money)
    if last_value < values[i]:
        money += kabu * values[i]
        kabu = 0
        last_value = values[i]
        #print("sell", kabu, money)
        
    #print((last_value > values[i:]), (last_value < values[i:]))
    #if (values[i] < values[i:]).sum() > 0:
    if (last_value > values[i:]).argmax() < (last_value < values[i:]).argmax():
        if values[i] == last_value:
            continue
        kabu += money // values[i]
        money %= values[i]
        last_value = values[i]
        #print("buy", kabu, money)
        
    if last_value == 10000:
        if (values[i] < values[i:]).sum() > 0:
            if (values[i] < values[i:]).argmax() > (values[i] > values[i:]).argmax():
                kabu += money // values[i]
                money %= values[i]
                last_value = values[i]
                #print("buy", kabu, money)
                
if kabu > 0:
    money += kabu * values[-1]
    
print(money)

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

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

Submission status: Wrong Answer

Solution code:
import sys

def f_buy(m, s, a):
  tmp = m//a
  return m-tmp*a, s+tmp

def f_sell(m, s, a):
  return m+s*a, 0

n = int(input())
la = list(map(int, input().split()))
lb = [0]*(n-1)
for i in range(n-1):
  if la[i+1]-la[i] > 0:
    lb[i] = 1
  if la[i+1]-la[i] < 0:
    lb[i] = -1

if lb.count(1) == 0:
  print(1000)
  sys.exit()

m = 1000
s = 0
frg = 0
for i in range(n-1):
  if lb[i] == 1:
    if frg != 1:
      m, s = f_buy(m, s, la[i])
    frg = 1
  if lb[i] == -1:
    if frg != -1:
      m, s = f_sell(m, s, la[i])
    frg = -1

if lb[n-2] == 1:
  m, s = f_sell(m, s, la[n-1])

print(m)

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]):
        b[i] = 1
        if(b[i-1] == 1):
            b[i-1] = 0
    if(a[i] > a[i+1]):
        b[i] = -1
        if(b[i-1] == -1):
            b[i-1] = 0
b[-1] = -1
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[0])

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())
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
    else:
        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])

for i in range(len(dp)):
    if i % 2 == 0:
        num_item += money // dp[i]
        if money // dp[i]==0:
            continue
        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:

def dp(index,mony,count,a,n):
    if index ==n-1:
        ans = mony +a[index]*count
        return ans

    index += 1
    if a[index] <=mony:
        if a[index] < max(a[index:]):
            x = dp(index,mony,count,a,n)
            y =dp(index,mony %a[index],mony // a[index],a,n)
            return max(x,y )
    else:
        return max(dp(index, mony, count, a, n), dp(index,  mony + a[index]*count,0, a, n))

    return mony

if __name__ == '__main__':
    n = int(input())
    a = [int(i) for i in input().split()]
    val = 0
    coun=0
    mony=1000
    print(dp(-1,1000,0,a,n))

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
while(A[::-1][j-2] < A[::-1][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())
A = list(map(int, input().split()))


# 最終日から考えることが早い
# 最終日が上げ相場の場合、最終日で全力で売っている
# 最終日が下げ相場の場合、何もしていない

money = 1000
kabu = 0

for i in range(N-1):
    # print(money, kabu)
    if A[i] < A[i+1]:
        kabu = money // A[i]
        money = money % A[i]
        # 最終日の場合、上げ相場であれば決済をする
        if i == N - 2:
            # print(money, kabu)
            money += kabu * A[N-1]
    elif A[i] > A[i+1]:
        money += kabu * A[i]
        kabu = 0

print(money)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
DP = [[0 for _1 in range(2)] for _ in range(N) ]

DP[0][0] = 1000
DP[0][1] = 1000 % A[0]
max_stock = 1000//A[0]

for j in range(1, N):
    today = A[j]

    DP[j][0] = max(max(DP[0:j][0]),DP[j-1][0], DP[j-1][1] + max_stock*today)
    DP[j][1] =  max(DP[j-1][1], DP[j-1][0] - (DP[j-1][0]//today)*today)
    max_stock = max(DP[j-1][0]//today, max_stock)




print(DP[N-1][0])

Submission status: Wrong Answer

Solution code:
MAX = 50000
INF = 1 << 60

n = int(input())
a = list(map(int, input().split()))
dp = [[-INF for j in range(MAX + 1)] for i in range(n)]
dp[0][0] = 1000
for k in range(1, MAX + 1):
    if 1000 - a[0] * k < 0:
        break
    dp[0][k] = 1000 - a[0] * k
# print(dp[0])
for i in range(1, n):
    for j in range(MAX + 1):
        # if dp[i][j] < 0:
        #     break
        dp[i][j] = max(dp[i][j], dp[i - 1][j])
        # 買うとき
        for k in range(1, MAX + 1):
            if j - k < 0:
                break
            if dp[i - 1][j - k] - a[i] * k < 0:
                break
            dp[i][j] = max(dp[i][j], dp[i - 1][j - k] - a[i] * k)
        # 売る時
        for k in range(1, MAX + 1):
            if j + k >= MAX + 1:
                break
            if dp[i - 1][j + k] < 0:
                break
            dp[i][j] = max(dp[i][j], dp[i - 1][j + k] + a[i] * k)
    # print(dp[i])
# print(dp)
ans = max(dp[-1])
print(max(ans, 1000))

Submission status: Wrong Answer

Solution code:
n = int(input())
a_li = list(map(int,input().split()))
low = a_li[0]
high = a_li[0]
old = a_li[0]
yen = 1000
for i in range(1,n):
    if low < a_li[i]:
        if old <= a_li[i]:
            high = a_li[i]
        else:
            div,yen = divmod(yen,low)
            yen += div*high
            low = a_li[i]
    old = a_li[i]
if low < high:
    div, yen = divmod(yen, low)
    yen += div * high
    low = a_li[i]
print(yen)

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
    else:
        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])

for i in range(len(dp)):
    if i % 2 == 0:
        num_item += money // dp[i]
        if money // dp[i]:
            continue
        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:
MAX = 5000
INF = 1 << 60

n = int(input())
a = list(map(int, input().split()))
dp = [[-INF for j in range(MAX + 1)] for i in range(n)]
dp[0][0] = 1000
for k in range(1, MAX + 1):
    if 1000 - a[0] * k < 0:
        break
    dp[0][k] = 1000 - a[0] * k
# print(dp[0])
for i in range(1, n):
    for j in range(MAX + 1):
        # if dp[i][j] < 0:
        #     break
        dp[i][j] = max(dp[i][j], dp[i - 1][j])
        # 買うとき
        for k in range(1, MAX + 1):
            if j - k < 0:
                break
            if dp[i - 1][j - k] - a[i] * k < 0:
                break
            dp[i][j] = max(dp[i][j], dp[i - 1][j - k] - a[i] * k)
        # 売る時
        for k in range(1, MAX + 1):
            if j + k >= MAX + 1:
                break
            if dp[i - 1][j + k] < 0:
                break
            dp[i][j] = max(dp[i][j], dp[i - 1][j + k] + a[i] * k)
    # print(dp[i])
# print(dp)
ans = max(dp[-1])
print(max(ans, 1000))

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>0:
    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(map(int, input().split()))
syoji = 1000
kabu = 0
kai = 0
for i in range(N):
  sw = 0
  if i < N-1:
    if kabu == 0 and A[i] < A[i+1]:
      sw = 1
  if kabu > 0 and kai < A[i]:
    syoji = syoji + kabu*A[i]
    kabu = 0 
  if sw == 1:#zengai
    for num in range (100):
      if syoji < num*A[i]:
        kabu = num-1
        syoji = syoji - (num-1)*A[i]
        kai = A[i]
        break
        
print(syoji)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
stuck=[0]*N
flag=False
for i in range(N):
    if A[N-i-1]>A[N-i-2]:
        base=A[N-i-1]
        break
else:
    print(1000)
    exit()
for i in range(N):
    money=A[N-i-1]
    if base<money and flag:
        stuck[i]=1
        flag=False
        base=money
    elif base>money and not flag:
        stuck[i]=-1
        flag=True
        base=money
flag=False
stuck=stuck[::-1]
money=1000
kabu=0
for i in range(N):
    if stuck[i]==-1:
        kabu=money//A[i]
        money-=A[i]*kabu
        flag=True
    elif stuck[i]==1:
        money+=A[i]*kabu
        flag=False
if flag:
    money+=A[-1]*kabu
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]
        else:
            money += kabu*a[i]
            kabu = 0


print(money)

Submission status: Wrong Answer

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

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

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

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

print(money)

Submission status: Wrong Answer

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

fp = A[0]
tmp = 0
c = 1000
stock = 0
IsSearchTop = False
first = True
for i in range(1,N):
    if first:
        if fp > A[i]:
            fp = A[i]
        elif fp < A[i]:
            stock += c // fp
            c -= stock * fp
            IsSearchTop = True
            first = False
            fp = A[i]
            if i == N - 1:
                c += stock * fp
            #print(1,stock, c)
    else:
        if IsSearchTop:
            if fp < A[i]:
                fp = A[i]
                if i == N-1:
                    c += stock * fp
            elif fp > A[i]:
                c += stock * fp
                stock = 0
                fp = A[i]
                IsSearchTop = False
                #print(2, stock, c)
        else:
            if fp > A[i]:
                fp = A[i]
            elif fp < A[i]:
                stock += c // fp
                c -= stock * fp
                IsSearchTop = True
                fp = A[i]
                if i == N - 1:
                    c += stock * fp
print(c)

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):
        #print(j,List[j],cnt)
        if cnt==0:
            #print("BBBBBBBB")
            KABU=M//List[j]
            M=M%List[j]
            MAE=List[j]
            #print("MAE",MAE)
        elif List[j]>MAE:
            M=M+(KABU*List[j])
            MAE=List[j]
            KABU=0
            cnt=0
        elif List[j]<MAE:
            KABU=M//List[j]
            M=M%List[j]
            MAE=List[j]
        else:
            pass
        #print(M,KABU)
        cnt+=1
        
    SUMList.append(M)
    #print("AAAAAAAAAAAAAAAAAAAAAA")
    
print(max(SUMList))

Submission status: Wrong Answer

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

n = int(input())

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

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import decimal
import itertools
from collections import deque
from functools import reduce
import heapq
import copy
n = int(input())
#n, k = map(int, sys.stdin.readline().split())
#s = input()
a = list(map(int, sys.stdin.readline().split()))

c = 1000
i = 0
while (i < n):
    ma = a[i]
    mi = a[i]
    mapo = i
    mipo = i
    j = 0
    while (i+j < n):
        if a[i+j] < mi:
            mi = a[i+j]
            mipo = i+j

        if a[i+j] > ma:
            if i+j == n-1:
                ma = a[i+j]
                mapo = i+j
                
            for k in range(i+j, n):
                if a[k] < a[i+j]:
                    ma = a[i+j]
                    mapo = i+j
                    f = 1
                    break

                if k == n-1:
                    f = 0

            if f == 1:
                break        

        j += 1



    if mapo == i:
        print(c)
        sys.exit()

    
    x = c // mi
    y = x * (ma - mi)
    c += y
    i += (j + 1)
    

print(c)

Submission status: Wrong Answer

Solution code:
import sys
N, *A = map(int, open(0).read().split())

money = 1_000

stock = 0
L = []
for i in range(len(A)):
    a = A[i]
    if i+1 < len(A) and a == A[i+1]:
        continue
    if stock == 0:
        stock = 10
        L.append(a)
        continue
    if L[-1] < a:
        stock = 0
        L.append(a)

# print(L)

if len(L) == 1:
    print(money)
    sys.exit()

if len(L) % 2:
    L = L[:-1]

stock = 0
for l in L:
    if stock == 0:
        stock = money // l
        money -= stock * l
    else:
        money += stock * l
        stock = 0

print(money)

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=a2[0]
mx=a2[0]
for i in range(1,len(a2)):
    #次の日の方が小さい場合キープ
    if mn>a2[i]:
        #キープ
        mn=min(a2[i],mn)
    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=max(a2[i],mx)
    else:
        #売る
        c+=mx*s
        s=0
        mx=99

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

Submission status: Wrong Answer

Solution code:
N = int(input())

A = list(map(int,input().split()))
reverseA = sorted(A,reverse = True)
money = 1000
stock = 0

if A == reverseA:
    print(money)
else:
    for i in range(N-1):
        if A[i] < A[i+1]:
            if(money // A[i] != 0):
                stock = money // A[i]
                money = money % A[i]
        elif A[i] > A[i+1]:
            money += stock * A[i]
            stock = 0
        else:
            None
        
    
    if stock > 0:
        money += stock * A[N-1]
        stock = 0
    
    print(money,stock)

Submission status: Wrong Answer

Solution code:
n=int(input())
ar=list(map(int,input().split()))
c=1000
p=0
cur=0
prev=0
for i in range(n):
    if i!=n-1 and ar[i+1]>ar[i]:
        prev=ar[i]
        cur=c//ar[i]
        c=c%ar[i]
##        print(i,'b')
    if i!=0 and ar[i]>ar[i-1]:
        p+=ar[i]*cur-prev*cur
        c+=cur*ar[i]
        cur=0
##        print(i,'s')
##    print(ar[i])
if cur!=0:
    c+=ar[-1]*cur
print(c)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

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

M = 1000
kabu = 0

cur = A[0]

for i in range(1,N):
    if cur > A[i]:
        # 持ってる株全部売る
        M = M + kabu * cur
        kabu = 0
    if cur < A[i]:
        # 所持金全部株に変える
        kabu = M // cur
        M = M % cur
    cur = A[i]

M = M + kabu * A[N-1]

print(M)

Submission status: Wrong Answer

Solution code:
def INT():
    return int(input())

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

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

N = INT()
A = LI()
ans = 1000

for i in range(1, N):
    tmp = ans
    purchase = 0
    if A[i] > A[i - 1]:
        for j in range(1000):
            if tmp - A[i - 1] < 0:
                break
            tmp -= A[i - 1]
            purchase += 1
        ans = max(ans, tmp + A[i] * purchase)
        
print(ans)

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
b = [0,0]
for i in range(n):
    a[A[i]] -= 1
    if a[A[i]] == 0: a.pop(A[i])

    flag = False
    if b[0] == 0 and b[1]!= A[i]:
        for j in a.keys():
            if A[i] < j:
                flag = True
                break
        if flag:
            cnt += money//A[i]
            money %= A[i]
            b = [A[i], A[i]]
    elif b[0] < A[i] and b[1]!=A[i]:
        money += cnt * A[i]
        cnt, b = 0, [0,A[i]]

print(money)

Submission status: Wrong Answer

Solution code:
a = int(input())
data = list(map(int, input().split()))
l =[]
money = 1000
stock = 0

for i in data:
  if i not in l:
    l += [i]

diff = []
dd = []
for i in range(len(l) - 1):
  if l[i] < l[i + 1]:
    if not diff:
      diff += [l[i + 1] - l[i]]
      dd += [[l[i + 1], l[i]]]
    elif diff[-1] < l[i + 1] - l[i]:
      diff += [l[i + 1] - l[i]]
      dd += [[l[i + 1], l[i]]]

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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
kane = 1000
kabu = 0
buy = A[0]
max = 0
flag = True

for i in range(1,N): 
  if(A[i-1] > A[i]):
    buy=A[i]
    flag = True
  #elif(temp_max < A[i] and buy < A[i]):
  elif(buy < A[i] and flag == True):
    max = A[i]
    kabu = int(kane/buy)
    kane = kane + kabu*(max-buy)  
    kabu = 0
    flag = False
print(kane)

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:
        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:
        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:
def inN():
    return int(input())
def inL():
    return list(map(int,input().split()))

n = inN()
a = inL()

kab = 0
mon = 1000
f = []
for i in range(n-1):
    if a[i+1] > a[i]:
        f.append(1)
    elif a[i+1] < a[i]:
        f.append(2)
    else:
        f.append(0)
f.append(2)
    
print(f)   
for i in range(n):

    if f[i] == 1 :
        kab += mon//a[i]
        mon = mon % a[i]
    elif f[i] == 2:
        mon += a[i]*kab
        kab = 0
    
print(mon)