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:
def laod_to_mill():
    days = int(input())
    prices = tuple(map(int, input().split()))

    if max(prices) == prices[0]:
        print(1000)
        return

    total = 1000
    ks = 0

    for d in range(days):
        if d == days - 1:
            total += ks * prices[d]
            break

        if prices[d] < prices[d + 1]:
            buy = total // prices[d]
            total -= buy * prices[d]
            ks += buy

        elif prices[d] > prices[d + 1]:
            total += ks * prices[d]
            ks = 0

    print(total)


def main():
    laod_to_mill()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def laod_to_mill():
    days = int(input())
    prices = tuple(map(int, input().split()))

    if max(prices) == prices[0]:
        print(1000)
        return

    total = 1000
    ks = 0

    for d in range(days):
        if d == days - 1:
            total += ks * prices[d]
            break

        if prices[d] < prices[d + 1]:
            buy = total // prices[d]
            total -= buy * prices[d]
            ks += buy

        if prices[d] > prices[d + 1]:
            total += ks * prices[d]
            ks = 0

    print(total)


def main():
    laod_to_mill()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def laod_to_mill():
    days = int(input())
    prices = tuple(map(int, input().split()))

    if max(prices) == prices[0]:
        print(1000)
        return

    total = 1000
    ks = 0

    for d in range(days):
        if d == days - 1:
            total += ks * prices[d]
            break

        total += ks * prices[d]
        ks = 0

        if prices[d] < prices[d + 1]:
            buy = total // prices[d]
            ks += buy
            total -= buy * prices[d]

    print(total)


def main():
    laod_to_mill()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def laod_to_mill():
    '''
    株の売買 D
    '''
    days = int(input())
    prices = tuple(map(int, input().split()))

    if max(prices) == prices[0]:
        print(1000)
        return

    total = 1000
    ks = 0

    for d in range(days):
        if d == days - 1:
            total += ks * prices[d]
            break

        total += ks * prices[d]
        ks = 0

        if prices[d] < prices[d + 1]:
            ks = total // prices[d]
            total %= prices[d]

    print(total)


def main():
    laod_to_mill()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def load_to_mill():
    days = int(input())
    prices = tuple(map(int, input().split()))

    if max(prices) == prices[0]:
        print(1000)
        return

    total = 1000
    ks = 0

    for d in range(days - 1):

        total += prices[d] * ks
        ks = 0

        if prices[d + 1] > prices[d]:
            ks = total // prices[d]
            total %= prices[d]

    if prices[-1] > prices[-2]:
        total += ks * prices[-1]

    print(total)


def main():
    load_to_mill()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def laod_to_mill():
    days = int(input())
    prices = tuple(map(int, input().split()))

    if max(prices) == prices[0]:
        print(1000)
        return

    total = 1000
    ks = 0

    for d in range(days - 1):
        total += prices[d] * ks
        ks = 0
     
        if prices[d + 1] > prices[d]:
            ks = total // prices[d]
            total %= prices[d]

    total += ks * prices[-1]
    print(total)


def main():
    laod_to_mill()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N=ii()
    _A=list(mi())
    A = []

    for a in _A:
        if len(A) > 0 and A[-1] == a: continue
        A.append(a)
    
    N = len(A)
    bottoms = []
    
    if N < 2:
        print(1000)
        exit()

    if A[0] < A[1]:
        bottoms.append(0)

    for i in range(N-1):
        if not i+2 < len(A): continue
        # print(A[i], A[i+1], A[i+2])
        if A[i] > A[i+1] and A[i+1] < A[i+2]:
            bottoms.append(i+1)
    
    money = 1000
    kabu = 0
    # print(bottoms)
    for bi in bottoms:
        bottom = A[bi]
        i = bi
        while i < N and A[i-1] > A[i]:
            i += 1
        
        top = A[i]

        # print(bi,i)
        # print(bottom,top)
        kabu += money//bottom
        money -= money//bottom * bottom
        
        money += kabu * top
        kabu = 0
        # print("money",money)
    
    print(money)

    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

money = 1000
stock = 0

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

print(money)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N=ii()
    A=list(mi()) + [0]
    # X = []
    # for i in range(80):
    #     if i % 2 == 0:
    #         X.append("100")
    #     else:
    #         X.append("200")
    
    # print(" ".join(X))

    dp = [[0] * (2*10**5+10) for _ in range(N+1)]
    x = 1000//A[0]
    dp[0][x] = 1000 - x * A[0]


    for i in range(x):
        dp[0][i] = 1000 - i * A[0]

    mx = x
    for i in range(N):
        _mx = mx
        for m in range(mx+1):
            for n in [0,m]:
                dp[i+1][m-n] = max(0,dp[i+1][m-n],dp[i][m] + A[i+1] * n)
                # assert dp[i+1][m-n] >= 0
            
            if A[i+1] != 0:
                j = dp[i][m] // A[i+1]
                if m + j < len(dp[i]):
                    dp[i+1][m+j] = max(0,dp[i+1][m+j],dp[i][m] - A[i+1] * j)
                    _mx = max(_mx,m+j)
                # assert dp[i+1][m+j] >= 0

        mx = _mx

    ans = 0
    for i in range(len(dp[N-1])):
        if dp[N-1][i] == 0: continue
        ans = max(ans, dp[N-1][i] + A[N-1] * i)

    # print(dp[3][10])
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
_,*a=map(int,open(0).read().split());x=1000
for i,j in zip(a,a[1:]):
 if j>i:x=x//i*j
print(x)

Submission status: Wrong Answer

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

syozi = 1000
kabu = 0

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

syozi += A[-1] * kabu

print(syozi)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
dp = [0] * n
dp[0] = 1000
for i in range(1, n):
  dp[i] = max(dp[i-1], dp[i-1] // a[i-1] * a[i] + dp[i-1] % a[i-1])
print(dp[i-1])

Submission status: Wrong Answer

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

syozi = 1000
kabu = 0

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

syozi += A[-1] * kabu

print(syozi)

Submission status: Wrong Answer

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

syozi = 1000
kabu = 0

for i in range(N-1):
  if A[i] < A[i+1]:
    kabu = syozi // A[i] 
    syozi = syozi % A[i]
  elif A[i] > A[i+1]:
    syozi += A[i] * kabu
    kabu = 0
  else:
    pass

syozi += A[-1] * kabu

print(syozi)

Submission status: Wrong Answer

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

else:
    print(money+int(num)*souba[N-1])

Submission status: Wrong Answer

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

#print(N)
#print(A)

syozi = 1000
kabu = 0

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

syozi += A[N-1] * kabu

print(syozi)

Submission status: Wrong Answer

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

#print(N)
#print(A)

syozi = 1000
kabu = 0

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

if A[N-2] < A[N-1]:
  syozi += A[N-1] * kabu
  kabu = 0

print(syozi)

Submission status: Wrong Answer

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

else:
    print(money+int(num)*souba[N-1])

Submission status: Wrong Answer

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

#print(N)
#print(A)

syozi = 1000
kabu = 0

for i in range(N-1):
#  print(str(i)+': '+ str(A[i]) + ', ' + str(kabu) + ', ' + str(syozi) )
  if A[i] < A[i+1]:
    kabu = syozi // A[i] 
    syozi = int( syozi % A[i] )
  elif A[i] > A[i+1]:
    syozi += A[i] * kabu
    kabu = 0
  else:
    pass
#  print( str(i)+': '+str(A[i]) + ', ' + str(kabu) + ', ' + str(syozi) )

if A[N-2] < A[N-1]:
  syozi += A[N-1] * kabu
  kabu = 0

print(syozi)

Submission status: Wrong Answer

Solution code:

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

nn=1000//100*5
dp=[[0]*nn for i in range(n)]

ni=1000//a[0]
for i in range(ni):    
    dp[0][i]=1000-a[0]*i

for k in range(1,n):
    for i in range(nn):
        xmax=0
        for ii in range(nn):
            x=dp[k-1][ii]+(ii-i)*a[k]
            if x<0:continue
            if dp[k-1][i]//a[k-1]<ii:break
            xmax=max(xmax,x) 
        dp[k][i]=xmax

print(dp[n-1][0])

Submission status: Wrong Answer

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

#print(N)
#print(A)

syozi = 1000
kabu = 0

for i in range(N-1):
#  print(str(i)+': '+ str(A[i]) + ', ' + str(kabu) + ', ' + str(syozi) )
  if A[i] < A[i+1]:
    kabu = syozi // A[i] 
    syozi = int( syozi % A[i] )
  elif A[i] > A[i+1]:
    syozi += A[i] * kabu
    kabu = 0
  else:
    pass
#  print( str(i)+': '+str(A[i]) + ', ' + str(kabu) + ', ' + str(syozi) )

if A[N-2] < A[N-1]:
  syozi += A[N-1] * kabu
  kabu = 0

print(syozi)

Submission status: Wrong Answer

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

else:
    print(money+int(num)*souba[N-1])

Submission status: Wrong Answer

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

yen = 1000
kabu_yen = 0
kabu_n = 0
last_buy = -1
for i in range(1,n):
    if A[i-1] < A[i]:
        tanka = A[i-1]
        m = yen // tanka
        yen -= tanka * m
        kabu_yen = tanka * m
        kabu_n = m
        last_buy = i-1

    elif A[i-1] > A[i]:
        tanka = A[i-1]
        m = kabu_n
        yen += tanka * m
        kabu_yen = 0
        kabu_n = 0

if kabu_n > 0:
    a = max(A[last_buy:])
    yen += a * kabu_n
print(yen)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, (input().split())))
a.append(0)
mon = 1000
kab = 0
x = 0
for i in range(n):
    if a[i] <= a[i+1]:
        kab += mon//a[i]
        mon += kab*(a[i+1]-a[i])
print(mon)

Submission status: Wrong Answer

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

#print(N)
#print(A)

syozi = 1000
kabu = 0

for i in range(N-1):
#  print(str(i)+': '+ str(A[i]) + ', ' + str(kabu) + ', ' + str(syozi) )
  if A[i] < A[i+1]:
    kabu = int( syozi / A[i] )
    syozi = int( syozi % A[i] )
  elif A[i] > A[i+1]:
    syozi += A[i] * kabu
    kabu = 0
  else:
    pass
#  print( str(i)+': '+str(A[i]) + ', ' + str(kabu) + ', ' + str(syozi) )

if A[N-2] < A[N-1]:
  syozi += A[N-1] * kabu
  kabu = 0

print(syozi)

Submission status: Wrong Answer

Solution code:

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

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

print(dp[-1])

Submission status: Wrong Answer

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

def check_increase(n,l):
    stock = []
    list_split = []
    for i in range(n-1):
        if l[i] < l[i+1]:
            stock.append(l[i])
            if i == n - 2:
                stock.append(l[i+1])
                list_split.append(stock)
        else:
            stock.append(l[i])
            list_split.append(stock)
            stock = []
            if i == n - 2:
                list_split.append([l[-1]])

    return list_split

a = sorted(set(a),key = a.index)
wallet = 1000
stock = 0
markets = check_increase(len(a),a)

for i in range(len(markets)):
    stock += wallet // markets[i][0]
    wallet %= markets[i][0]
    wallet += stock * markets[i][-1]
    stock = 0

print(wallet)

Submission status: Wrong Answer

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

def main():
    money = 1000
    n = 0
    
    x = a[0]
    for i in range(1, len(a)):
        if (x < a[i]):   # 買う
            n = money // a[i-1]
            money += (a[i] - a[i-1]) * n
            x = a[i]

    print(money)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
N = I()
A = LI()
okane = 1000
stock = 0
for i in range(N-1):
    if A[i] < A[i+1]:
        #kau
        stock = okane//A[i]
        okane = okane%A[i]
    elif A[i] > A[i+1]:
        #uru
        okane += stock*A[i]
        stock = 0
    else:
        continue
print(okane+stock*A[-1])

Submission status: Wrong Answer

Solution code:
ma = lambda :map(int,input().split())
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
n = ni()
A = list(ma())
tot = 1000
kab = 0
for i in range(n-1):
    tot += A[i]*kab
    if A[i] > A[i+1]:
        pass
    if A[i] <= A[i+1]:#ここで換金して次に増えるなら
         tot,kab = divmod(A[i],tot)
tot+=A[-1]*kab
print(tot)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
money = 1000
dp = a
dp[0] = 1000
for i in range(1, n):
    dp[i] = dp[i -1]
    for j in range(i -1):
        V = dp[j] / a[j]
        W = dp[j] + (a[i] -a[j])*V
        dp[i] = max(dp[i], W)
print(dp[-1])

Submission status: Wrong Answer

Solution code:
n,*a=map(int,open(0).read().split())
ans=1000
num= 0
for i in range(n):
  if i == n-1:
    if a[i-1]<=a[i]:
      ans += a[i]*num
  elif a[i]<a[i+1] and a[i+1]<=ans:
    num = ans//a[i]
    ans = ans%a[i]
  elif a[i]<a[i+1] and a[i+1]>ans:
    continue
  elif a[i] == a[i+1]:
    continue
  else:
    ans += num*a[i]
  
print(ans)

Submission status: Wrong Answer

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

else:
    print(money+num*souba[N-1])

Submission status: Wrong Answer

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

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

c=1000
s=0
mn=201
mx=99
for i in a2:
    #その方が小さい場合キープ
    if mn>i:
        mn=i
    else:
        #買う
        s=c//mn
        c-=s*mn
        mn=201
        continue
    #次の方が大きい場合キープ
    if mx<i:
        mx=i
    else:
        #売る
        c+=mx*s
        s=0
        mx=99

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

Submission status: Wrong Answer

Solution code:
n,*a=map(int,open(0).read().split())
ans=1000
num= 0
for i in range(n):
  if i == n-1:
    if a[i-1]<a[i]:
      ans += a[i]*num
  elif a[i]<a[i+1] and a[i+1]<ans:
    num = ans//a[i]
    ans = ans%a[i]
  elif a[i]<a[i+1] and a[i+1]>ans:
    continue
  elif a[i] == a[i+1]:
    continue
  else:
    ans += num*a[i]
  
print(ans)

Submission status: Wrong Answer

Solution code:
n,*a=map(int,open(0).read().split())
ans=1000
num= 0
for i in range(n):
  if i == n-1:
    if a[i-1]<a[i]:
      ans += a[i]*num
  elif a[i]<a[i+1] and a[i+1]<ans:
    num = ans//a[i]
    ans = ans%a[i]
    print(i,num,ans)
  elif a[i]<a[i+1] and a[i+1]>ans:
    continue
  elif a[i] == a[i+1]:
    continue
  else:
    ans += num*a[i]
  
print(ans)

Submission status: Wrong Answer

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

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

c=1000
s=0
mn=201
mx=99
for i in a2:
    #その方が小さい場合キープ
    if mn>i:
        mn=i
    else:
        #買う
        s=c//mn
        c-=s*mn
        mn=201
    #次の方が大きい場合キープ
    if mx<i:
        mx=i
    else:
        #売る
        c+=mx*s
        s=0
        mx=99

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

Submission status: Wrong Answer

Solution code:
N = int(input())
s_list = list(input().split())
money = 1000
stock = 0

for i in range(N):

  # Last day
  if (i == N-1):
    money += stock * int(s_list[i])
    stock = 0
    break

  # Stock price tomorrow is higher than today
  if (int(s_list[i+1]) > int(s_list[i])):
    stock = stock + int(money / int(s_list[i]))
    money = money - (int(s_list[i]) * int(money / int(s_list[i])))
    continue

  # Stock price tomorrow is lower than or equal to today
  if (int(s_list[i+1]) <= int(s_list[i])):
    money = money + (int(s_list[i]) * stock)
    stock = 0
    continue

print("money: {}".format(money))

Submission status: Wrong Answer

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

k_y = [1000]
yen = 1000
resyen = 1000
kabu_max = 0
for i in range(n):
	#株を売り払うケース
	newyen = max( yen, kabu_max * a[i] + resyen)
	
	#株を最大買うケース
	kabu_max_new = max( kabu_max + resyen // a[i], yen // a[i] )
	if kabu_max_new == yen // a[i]:
		resyen = yen % a[i]
	yen = newyen
	kabu_max = kabu_max_new
	#print(kabu_max,yen,resyen)
print( yen )

Submission status: Wrong Answer

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

k_y = [1000]
yen = 1000
resyen = 1000
kabu_max = 0
for i in range(n):
	#株を売り払うケース
	newyen = max( yen, kabu_max * a[i] + resyen)
	
	#株を最大買うケース
	kabu_max_new = max( kabu_max, yen // a[i] )
	if kabu_max_new == yen // a[i]:
		resyen = yen % a[i]
	yen = newyen
	kabu_max = kabu_max_new
	#print(kabu_max,yen,resyen)
	
print( yen )

Submission status: Wrong Answer

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

yen = 1000
kabu_yen = 0
kabu_n = 0
for i in range(1,n):
    if A[i-1] < A[i]:
        tanka = A[i-1]
        m = yen // tanka
        yen -= tanka * m
        kabu_yen = tanka * m
        kabu_n = m

    elif A[i-1] > A[i]:
        tanka = A[i-1]
        m = kabu_n
        yen += tanka * m
        kabu_yen = 0
        kabu_n = 0

if kabu_n>0:
    yen += A[-1] * kabu_n
print(yen)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
money = 1000
start = 0
while True:
    for i in range(start,N):
        if A[i] > A[start]:
            stock = money // min(A[start:i])
            amari = money % min(A[start:i])
            for j in range(i,N):
                if j == N-1:
                    money = amari + stock*max(A[i:N])
                    print(money)
                    exit()
                if A[j] < A[i] or j == N-1:
                    money = amari + stock*max(A[i:j])
                    stock = 0
                    amari = 0
                    start = j
                    break
            break
        if i == N-1:
            print(money)
            exit()

Submission status: Wrong Answer

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

k_y = [1000]
yen = 1000
resyen = 1000
kabu_max = 0
for i in range(n):
	#株を売り払うケース
	newyen = max( yen, kabu_max * a[i] + resyen)
	
	#株を最大買うケース
	kabu_max_new = max( kabu_max, yen // a[i] )
	if kabu_max_new == yen // a[i]:
		resyen = yen % a[i]
	newyen = max( yen, kabu_max * a[i] + resyen)

	yen = newyen
	kabu_max = kabu_max_new
	#print(kabu_max,yen,resyen)
	
print( yen )

Submission status: Wrong Answer

Solution code:
def solve():
    N=int(input())
    A=list(map(int,input().split()))
    mini,maxi=min(A),max(A)
    cnt=1000//mini
    print(maxi*cnt+1000%mini)

if __name__=="__main__":
    solve()

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
 
A = list(map(int,input().split()))
 
a = 0
b = 0
Money = 1000
 
for i in A:
  if a == 0:
    a = i
    continue
  if b <= i:
    b = i
    continue
  else:
    if a < b:
      Money = Money // a * b + Money % a
    a = b = i
    
if a < b:
      Money = Money // a * b + Money % a
print(Money)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict,deque
import math
def gcd(a,b):
    return b if not a%b else gcd(b,a%b)
def lcm(a,b):
    return (a*b)//gcd(a,b)

def main():
    n = int(input())
    a=[int(i) for i in input().split()]
    stocks = 0
    money = 1000
    for i in range(n-1):
        if(a[i] < a[i+1]):
            stocks = money//a[i]
        money += stocks*(a[i+1]-a[i])
    print(money)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
 
A = list(map(int,input().split()))
 
a = 0
b = 0
Money = 1000
 
for i in range(len(A)):
  if a == 0:
    a = A[i]
    continue
  elif b <= A[i]:
    b = A[i]
    continue
  else:
    if a < b:
      Money = Money // a * b + Money % a
    a = b = A[i]
    
if a < b:
      Money = Money // a * b + Money % a
print(Money)

Submission status: Wrong Answer

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

money = 1000

for i in range(1,   n-1):
    s = 0
    if a[i] < a[i + 1]:
        s = money // a[i]
    money += (a[i + 1] - a[i]) * s
print(money)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
money  = 1000
stock = 0
min_price = a[0]
max_price = a[0]
is_first_time_of_drop = True
for i in range(n):
    if a[i] >= max_price:
        max_price = a[i]
        if i == n - 1:
            money = (money // min_price) * max_price + money % min_price
    else:
        if is_first_time_of_drop:
            money = (money // min_price) * max_price + money % min_price
            min_price = a[i]
            max_price = a[i]
            is_first_time_of_drop = False
        else:
            if a[i] <= min_price:
                min_price = a[i]
                max_price = a[i]
            else:
                is_first_time_of_drop = True
print(money)

Submission status: Wrong Answer

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

money = 1000

for i in range(1,   n-1):
    s = 0
    if a[i] < a[i + 1]:
        s = money / a[i]
    money += (a[i + 1] - a[i]) * s
print(money)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
m = 1000
i = 0
while i < n - 1:
    for j in range(i + 1, n):
        if a[i] < a[j]:
            m = m // a[i] * a[j] + m % a[i]
        else:
            i = j
            break
print(m)

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

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

money = 1000

for i in range(n-1):
    s = 0
    if a[i] < a[i + 1]:
        s = money / a[i]
    money += (a[i + 1] - a[i]) * s
print(money)

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 = int(M - X * A[i])
    
    M = M + X * A[i+1]
    X = 0

    print(A[i+1],int(M))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a_cur = a[0]

m = 1000
s = 0

for i in range(1, n):
    a_next = a[i]
    if a_cur < a_next:
        # buy
        s += m // a_cur
        m -= s * a_cur
    else:
        # sell
        m += s * a_cur
        s = 0
    a_cur = a_next
m += s * a_cur
print(m)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a_cur = a[0]

m = 1000
s = 0

for i in range(1, n):
    a_next = a[i]
    if a_cur < a_next:
        # buy current and sell next
        s = m // a_cur
        m -= s * a_cur
    else:
        m += s * a_cur
        s = 0
    a_cur = a_next
m += s * a_cur
print(m)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

a = 0
b = 0
Money = 1000

for i in range(len(A)):
  if a == 0:
    a = A[i]
    continue
  if b <= A[i]:
    b = A[i]
    continue
  else:
    if a < b:
      Money = Money // a * b + Money % a
    a = b = A[i]
    
if a < b:
      Money = Money // a * b + Money % a
print(Money)