Problem:


Score : 600 points

Problem Statement

The squirrel Chokudai has N acorns.
One day, he decides to do some trades in multiple precious metal exchanges to make more acorns.

His plan is as follows:

Get out of the nest with N acorns in his hands.

Go to Exchange A and do some trades.

Go to Exchange B and do some trades.

Go to Exchange A and do some trades.

Go back to the nest.

In Exchange X (X = A, B), he can perform the following operations any integer number of times (possibly zero) in any order:

Lose g_{X} acorns and gain 1 gram of gold.

Gain g_{X} acorns and lose 1 gram of gold.

Lose s_{X} acorns and gain 1 gram of silver.

Gain s_{X} acorns and lose 1 gram of silver.

Lose b_{X} acorns and gain 1 gram of bronze.

Gain b_{X} acorns and lose 1 gram of bronze.

Naturally, he cannot perform an operation that would leave him with a negative amount of acorns, gold, silver, or bronze.

What is the maximum number of acorns that he can bring to the nest?
Note that gold, silver, or bronze brought to the nest would be worthless because he is just a squirrel.

Constraints

1 \leq N \leq 5000

1 \leq g_{X} \leq 5000

1 \leq s_{X} \leq 5000

1 \leq b_{X} \leq 5000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
g_A s_A b_A
g_B s_B b_B

Output

Print the maximum number of acorns that Chokudai can bring to the nest.

Sample Input 1

23
1 1 1
2 1 1

Sample Output 1

46

He can bring 46 acorns to the nest, as follows:

In Exchange A, trade 23 acorns for 23 grams of gold. {acorns, gold, silver, bronze}={ 0,23,0,0 }

In Exchange B, trade 23 grams of gold for 46 acorns. {acorns, gold, silver, bronze}={ 46,0,0,0 }

In Exchange A, trade nothing. {acorns, gold, silver, bronze}={ 46,0,0,0 }

He cannot have 47 or more acorns, so the answer is 46.



Sample input:
23
1 1 1
2 1 1


Sample output:
46

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
change_a = [i for i in range(3) if a[i] < b[i]]
change_b = [i for i in range(3) if a[i] > b[i]]
if len(change_a) == 0:
  if len(change_b) == 0:
    print(n)
  elif len(change_b) == 1:
    i = n // b[change_b[0]]
    n = n % b[change_b[0]]
    n += i * a[change_b[0]]
    print(n)
  elif len(change_b) == 2:
    tmp = 0
    for i in range(5001):
      m = n
      m -= i * b[change_b[0]]
      if m < 0:
        break
      j = m // b[change_b[1]]
      m = m % b[change_b[1]]
      m += i * a[change_b[0]] + j * a[change_b[1]]
      tmp = max(tmp, m)
    print(tmp)
  else:      
    tmp = 0
    for i in range(5001):
      for j in range(5001):
        m = n
        m -= i * b[change_b[0]]
        if m < 0:
          break
        m -= j * b[change_b[1]]
        if m < 0:
          break
        k = m // b[change_b[2]]
        m = m % b[change_b[2]]
        m += i * a[change_b[0]] + j * a[change_b[1]] + k * a[change_b[2]]
        tmp = max(tmp, m)
elif len(change_a) == 1:
  gsb = n // a[change_a[0]]
  n = n % a[change_a[0]]
  n += gsb * b[change_a[0]]
  if len(change_b) == 0:
    print(n)
  elif len(change_b) == 1:
    gsb = n // b[change_b[0]]
    n = n % b[change_b[0]]
    n += gsb * a[change_b[0]]
    print(n)
  elif len(change_b) == 2:
    tmp = 0
    for i in range(5001):
      m = n
      m -= i * b[change_b[0]]
      if m < 0:
        break
      j = m // b[change_b[1]]
      m = m % b[change_b[1]]
      m += i * a[change_b[0]] + j * a[change_b[1]]
      tmp = max(tmp, m)
    print(tmp)
elif len(change_a) == 2:
  tmp = 0
  for i in range(5001):
    m = n
    m -= i * a[change_a[0]]
    if m < 0:
      break
    j = m // a[change_a[1]]
    m = m % a[change_a[1]]
    m += i * b[change_a[0]] + j * b[change_a[1]]
    tmp = max(tmp, m)
  n = tmp
  if len(change_b) == 0:
    print(n)
  elif len(change_b) == 1:
    gsb = n // b[change_b[0]]
    n = n % b[change_b[0]]
    n += gsb * a[change_b[0]]
    print(n)
else:    
  tmp = 0
  for i in range(5001):
    for j in range(5001):
      m = n
      m -= i * a[change_a[0]]
      if m < 0:
        break
        m -= j * a[change_a[1]]
      if m < 0:
        break
      k = m // a[change_a[2]]
      m = m % a[change_a[2]]
      m += i * b[change_a[0]] + j * b[change_a[1]] + k * b[change_a[2]]
      tmp = max(tmp, m)
  print(tmp)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
change_a = [i for i in range(3) if a[i] < b[i]]
change_b = [i for i in range(3) if a[i] > b[i]]
if len(change_a) == 0:
  if len(change_b) == 0:
    print(n)
  elif len(change_b) == 1:
    i = n // b[change_b[0]]
    n = n % b[change_b[0]]
    n += i * a[change_b[0]]
    print(n)
  elif len(change_b) == 2:
    tmp = 0
    for i in range(5001):
      m = n
      m -= i * b[change_b[0]]
      if m < 0:
        break
      j = m // b[change_b[1]]
      m = m % b[change_b[1]]
      m += i * a[change_b[0]] + j * a[change_b[1]]
      tmp = max(tmp, m)
    print(tmp)
  else:      
    tmp = 0
    for i in range(5001):
      for j in range(5001):
        m = n
        m -= i * b[change_b[0]]
        if m < 0:
          break
        m -= j * b[change_b[1]]
        if m < 0:
          break
        k = m // b[change_b[2]]
        m = m % b[change_b[2]]
        m += i * a[change_b[0]] + j * a[change_b[1]] + k * a[change_b[2]]
        tmp = max(tmp, m)
elif len(change_a) == 1:
  gsb = n // a[change_a[0]]
  n = n % a[change_a[0]]
  n += gsb * b[change_a[0]]
  if len(change_b) == 0:
    print(n)
  elif len(change_b) == 1:
    gsb = n // b[change_b[0]]
    n = n % b[change_b[0]]
    n += gsb * a[change_b[0]]
    print(n)
  elif len(change_b) == 2:
    tmp = 0
    for i in range(5001):
      m = n
      m -= i * b[change_b[0]]
      if m < 0:
        break
      j = m // b[change_b[1]]
      m = m % b[change_b[1]]
      m += i * a[change_b[0]] + j * a[change_b[1]]
      tmp = max(tmp, m)
    print(tmp)
elif len(change_a) == 2:
  tmp = 0
  for i in range(5001):
    m = n
    m -= i * a[change_a[0]]
    if m < 0:
      break
      j = m // a[change_a[1]]
      m = m % a[change_a[1]]
      m += i * b[change_a[0]] + j * b[change_a[1]]
      tmp = max(tmp, m)
  n = tmp
  if len(change_b) == 0:
    print(n)
  elif len(change_b) == 1:
    gsb = n // b[change_b[0]]
    n = n % b[change_b[0]]
    n += gsb * a[change_b[0]]
    print(n)
else:    
  tmp = 0
  for i in range(5001):
    for j in range(5001):
      m = n
      m -= i * a[change_a[0]]
      if m < 0:
        break
        m -= j * a[change_a[1]]
      if m < 0:
        break
        k = m // a[change_a[2]]
        m = m % a[change_a[2]]
        m += i * b[change_a[0]] + j * b[change_a[1]] + k * b[change_a[2]]
        tmp = max(tmp, m)
  print(tmp)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
change_a = [i for i in range(3) if a[i] < b[i]]
change_b = [i for i in range(3) if a[i] > b[i]]
if len(change_a) == 0:
  if len(change_b) == 0:
    print(n)
  elif len(change_b) == 1:
    gsb = n // b[change_b[0]]
    n = n % b[change_b[0]]
    n += gsb * a[change_b[0]]
    print(n)
  elif len(change_b) == 2:
    tmp = 0
    for i in range(5001):
      m = n
      m -= i * b[change_b[0]]
      if m < 0:
        break
      j = m // b[change_b[1]]
      m = m % b[change_b[1]]
      m += i * a[change_b[0]] + j * a[change_b[1]]
      tmp = max(tmp, m)
    print(tmp)
  else:
    for i in range(5001):
      tmp = 0
      for j in range(5001):
        m = n
        m -= i * b[change_b[0]]
        if m < 0:
          break
        m -= j * b[change_b[1]]
        if m < 0:
          break
        k = m // b[change_b[2]]
        m = m % b[change_b[2]]
        m += i * a[change_b[0]] + j * a[change_b[1]] + k * a[change_b[2]]
        tmp = max(tmp, m)
elif len(change_a) == 1:
  gsb = n // a[change_a[0]]
  n = n % a[change_a[0]]
  n += gsb * b[change_a[0]]
  if len(change_b) == 0:
    print(n)
  elif len(change_b) == 1:
    gsb = n // b[change_b[0]]
    n = n % b[change_b[0]]
    n += gsb * a[change_b[0]]
    print(n)
  elif len(change_b) == 2:
    tmp = 0
    for i in range(5001):
      m = n
      m -= i * b[change_b[0]]
      if m < 0:
        break
      j = m // b[change_b[1]]
      m = m % b[change_b[1]]
      m += i * a[change_b[0]] + j * a[change_b[1]]
      tmp = max(tmp, m)
    print(tmp)
elif len(change_a) == 2:
  tmp = 0
  for i in range(5001):
    m = n
    m -= i * a[change_a[0]]
    if m < 0:
      break
      j = m // a[change_a[1]]
      m = m % a[change_a[1]]
      m += i * b[change_a[0]] + j * b[change_a[1]]
      tmp = max(tmp, m)
  n = tmp
  if len(change_b) == 0:
    print(n)
  elif len(change_b) == 1:
    gsb = n // b[change_b[0]]
    n = n % b[change_b[0]]
    n += gsb * a[change_b[0]]
    print(n)
else:
  for i in range(5001):
    tmp = 0
    for j in range(5001):
      m = n
      m -= i * a[change_a[0]]
      if m < 0:
        break
        m -= j * a[change_a[1]]
      if m < 0:
        break
        k = m // a[change_a[2]]
        m = m % a[change_a[2]]
        m += i * b[change_a[0]] + j * b[change_a[1]] + k * b[change_a[2]]
        tmp = max(tmp, m)
  print(tmp)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
U = 5000 * 5000 + 10

inf = 10 ** 18
dp1 = [-inf] * U
dp1[0] = N
for a, b in zip(A, B):
    for i in range(N - a + 1):
        dp1[i + a] = max(dp1[i + a], dp1[i] + b - a)

for i in range(N + 1):
    N = max(N, dp1[i])
print(N)

dp2 = [-inf] * U
dp2[0] = N
for a, b in zip(A, B):
    for i in range(N - b + 1):
        dp2[i + b] = max(dp2[i + b], dp2[i] + a - b)

for i in range(N + 1):
    N = max(N, dp2[i])

print(N)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
U = 5000 * 5000 + 10

inf = 10 ** 18
dp1 = [-inf] * U
dp1[0] = N
for a, b in zip(A, B):
    for i in range(N - a + 1):
        dp1[i + a] = max(dp1[i + a], dp1[i] + b - a)

for i in range(N + 1):
    N = max(N, dp1[i])
print(N)

dp2 = [-inf] * U
dp2[0] = 0
for a, b in zip(A, B):
    for i in range(N - b + 1):
        dp2[i + b] = max(dp2[i + b], dp2[i] + a - b)

for i in range(N + 1):
    N = max(N, dp2[i])

print(N)

Submission status: Wrong Answer

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


# Aで金属に交換、Bでまず金属をどんぐりに、どんぐりを別の金属に、Aで金属をどんぐりにする感じ
A_to_B = []
B_to_A = []
for i, (a, b) in enumerate(zip(GSB_a, GSB_b)):
    if a < b:
        A_to_B.append((b / a, -a, i))
    elif b < a:
        B_to_A.append((a / b, -b, i))
A_to_B.sort(reverse=True)
B_to_A.sort(reverse=True)

# Aでどんぐり->金属
material = [0, 0, 0]
for i in range(len(A_to_B)):
    _, mat, ind = A_to_B[i]
    div, N = divmod(N, -mat)
    material[ind] += div

# Bで金属->どんぐり
for i in range(3):
    N += material[i] * GSB_b[i]

# Bでどんぐり->金属
material = [0, 0, 0]
for i in range(len(B_to_A)):
    _, mat, ind = B_to_A[i]
    div, N = divmod(N, -mat)
    material[ind] += div

# Aで金属->どんぐり
for i in range(3):
    N += material[i] * GSB_a[i]

print(N)

Submission status: Wrong Answer

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


# Aで金属に交換、Bでまず金属をどんぐりに、どんぐりを別の金属に、Aで金属をどんぐりにする感じ
A_to_B = []
B_to_A = []
for i, (a, b) in enumerate(zip(GSB_a, GSB_b)):
    if a < b:
        A_to_B.append((b / a, -a, i))
    elif b < a:
        B_to_A.append((a / b, -b, i))
A_to_B.sort()
B_to_A.sort()

# Aでどんぐり->金属
material = [0, 0, 0]
for i in range(len(A_to_B)):
    _, mat, ind = A_to_B[i]
    div, N = divmod(N, -mat)
    material[ind] += div
# Bで金属->どんぐり
for i in range(3):
    N += material[i] * GSB_b[i]
# Bでどんぐり->金属
material = [0, 0, 0]
for i in range(len(B_to_A)):
    _, mat, ind = B_to_A[i]
    div, N = divmod(N, -mat)
    material[ind] += div
# Aで金属->どんぐり
for i in range(3):
    N += material[i] * GSB_a[i]

print(N)

Submission status: Wrong Answer

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

if len([i for i, (a, b) in enumerate(zip(A, B)) if a != b]) == 0:
    print(N)
    exit()

M = N
if len([i for i, (a, b) in enumerate(zip(A, B)) if a < b]) == 1:
    i = [i for i, (a, b) in enumerate(zip(A, B)) if a < b][0]

    for k in range(N // A[i] + 1):
        D = N - k * A[i]
        D += k * B[i]
        M = max(M, D)
elif len([i for i, (a, b) in enumerate(zip(A, B)) if a < b]) == 2:
    i, j = [i for i, (a, b) in enumerate(zip(A, B)) if a < b]

    for k in range(N // B[i] + 1):
        D = N - k * B[i]
        l, D = divmod(D, B[j])

        D += k * A[i]
        D += l * A[j]

        M = max(M, D)
elif len([i for i, (a, b) in enumerate(zip(A, B)) if a < b]) == 3:
    for g in range(N // A[0] + 1):
        for s in range(N // A[1] + 1):
            D = N - g * A[0] - s * A[1]

            if D < 0:
                break

            q, r = divmod(D, A[2])

            D += g * B[0]
            D += s * B[1]

            r += g * B[0]
            r += s * B[1]
            r += q * B[2]

            M = max(M, D, r)

N = M
A, B = B, A
if len([i for i, (a, b) in enumerate(zip(A, B)) if a < b]) == 1:
    i = [i for i, (a, b) in enumerate(zip(A, B)) if a < b][0]

    for k in range(N // A[i] + 1):
        D = N - k * A[i]
        D += k * B[i]
        M = max(M, D)
elif len([i for i, (a, b) in enumerate(zip(A, B)) if a < b]) == 2:
    i, j = [i for i, (a, b) in enumerate(zip(A, B)) if a < b]

    for k in range(N // B[i] + 1):
        D = N - k * B[i]
        l, D = divmod(D, B[j])

        D += k * A[i]
        D += l * A[j]

        M = max(M, D)
elif len([i for i, (a, b) in enumerate(zip(A, B)) if a < b]) == 3:
    for g in range(N // A[0] + 1):
        for s in range(N // A[1] + 1):
            D = N - g * A[0] - s * A[1]

            if D < 0:
                break

            q, r = divmod(D, A[2])

            D += g * B[0]
            D += s * B[1]

            r += g * B[0]
            r += s * B[1]
            r += q * B[2]

            M = max(M, D, r)

print(M)

Submission status: Wrong Answer

Solution code:
n = int(input())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
a = []
b = []
for i, j in zip(aa, bb):
    if i < j:
        a.append((i, j))
    if j < i:
        b.append((j, i))

def solve(li, n):
    if len(li)==0:
        return 0
    if len(li)==1:
        return (li[0][1]-li[0][0]) * n//li[0][0]
    if len(li)==2:
        a = li[0]
        b = li[1]
        ma = 0
        for i in range(n//a[0]+1):
            tmp = (a[1]-a[0])*i + (b[1]-b[0])*((n-a[0]*i)//b[0])
            if tmp > ma:
                ma = tmp
        return ma
    return -1

gain = solve(a, n)
gain2 = solve(b, n+gain)
print(n+gain+gain2)

Submission status: Wrong Answer

Solution code:
n = int(input())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
a = []
b = []
for i, j in zip(aa, bb):
    if i < j:
        a.append((i, j))
    if j < i:
        b.append((j, i))

def solve(li, n):
    if len(li)==0:
        return 0
    if len(li)==1:
        return (li[0][1]-li[0][0]) * n//li[0][0]
    if len(li)==2:
        a = li[0]
        b = li[1]
        ma = 0
        for i in range(n//a[0]+1):
            tmp = (a[1]-a[0])*i + (b[1]-b[0])*((n-a[0]*i)//b[0])
            if tmp > ma:
                ma = tmp
        return ma
    a = li[0]
    b = li[1]
    c = li[2]
    ma = 0
    for i in range(n//a[0]+1):
        nn = n-a[0]*i
        for j in range(nn//b[0]+1):
            tmp = (a[1]-a[0])*i + (b[1]-b[0])*j + (c[1]-c[0])*((nn-b[0]*j)//c[0])
            if tmp > ma:
                ma = tmp
    return ma

gain = solve(a, n)
gain2 = solve(b, n+gain)
print(n+gain+gain2)

Submission status: Wrong Answer

Solution code:
n = int(input())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
a = []
b = []
for i, j in zip(aa, bb):
    if i < j:
        a.append((i, j))
    if j < i:
        b.append((j, i))

def solve(li, n):
    if len(li)==0:
        return 0
    if len(li)==1:
        return (li[0][1]-li[0][0]) * n//li[0][0]
    if len(li)==2:
        a = li[0]
        b = li[1]
        ma = 0
        for i in range(n//a[0]+1):
            tmp = (a[1]-a[0])*i + (b[1]-b[0])*((n-a[0]*i)//b[0])
            if tmp > ma:
                ma = tmp
        return ma
    a = li[0]
    b = li[1]
    c = li[2]
    ma = 0
    for i in range(n//a[0]+1):
        nn = n-a[0]*i
        for j in range(nn//b[0]+1):
            tmp = (a[1]-a[0])*i + (b[1]-b[0])*j + (c[1]-c[0])*((nn-b[0]*j)//c[0])
            if tmp > ma:
                ma = tmp
    return ma

gain = solve(a, n)
ans = solve(b, n+gain) + n + gain
print(ans)

Submission status: Wrong Answer

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

def calc(fr, to):
    ret = N
    for g in range(N // fr[0] + 1):
        for s in range(N // fr[1] + 1):
            D = N - g * fr[0] - s * fr[1]

            if D < 0:
                break

            q, r = divmod(D, fr[2])

            D += g * to[0]
            D += s * to[1]

            r += g * to[0]
            r += s * to[1]
            r += q * to[2]

            ret = max(ret, D, r)
    return ret

print(max(calc(A, B), calc(B, A)))

Submission status: Wrong Answer

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

def calc(fr, to):
    ret = N
    for g in range(N // fr[0] + 1):
        for s in range(N // fr[1] + 1):
            D = N - g * fr[0] - s * fr[1]

            if D < 0:
                break

            b = 0
            if fr[2] < to[2]:
                b, D = divmod(D, fr[2])

            D += g * to[0]
            D += s * to[1]
            D += b * to[2]

            ret = max(ret, D)
    return ret

print(max(calc(A, B), calc(B, A)))

Submission status: Wrong Answer

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

def calc(fr, to):
    ret = N
    for g in range(N // fr[0] + 1):
        for s in range(N // fr[1] + 1):
            D = N - g * fr[0] - s * fr[1]

            if D < 0:
                break

            b, D = divmod(D, fr[2])

            D += g * to[0]
            D += s * to[1]
            D += b * to[2]

            ret = max(ret, D)
    return ret

print(max(calc(A, B), calc(B, A)))

Submission status: Wrong Answer

Solution code:
N = int(input())
fr = tuple(map(int, input().split()))
to = tuple(map(int, input().split()))

ans = N
for g in range(N // fr[0] + 1):
    for s in range(N // fr[1] + 1):
        D = N - g * fr[0] - s * fr[1]

        if D < 0:
            break

        b, D = divmod(D, fr[2])

        q, r = divmod(g, to[0])
        D += q
        g = r

        q, r = divmod(s, to[1])
        D += q
        s = r

        q, r = divmod(b, to[2])
        D += q
        s = r

        q, r = divmod(g, fr[0])
        D += q

        q, r = divmod(s, fr[1])
        D += q

        q, r = divmod(b, fr[2])
        D += q

        ans = max(ans, D)

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
l1=[i for i in range(3) if B[i]>A[i]]
l2=[i for i in range(3) if B[i]<A[i]]
r=[B[i]-A[i] for i in range(3)]
def b(l):
    global N
    if len(l)==3:
        M=0
        for i in range(N//A[0]+1):
            for j in range((N-i*A[0])//A[1]+1):
                k=(N-i*A[0]-j*A[1])//A[2]
                M=max(M,i*B[0]+j*B[1]+k*B[2]+(N-i*A[0]-j*A[1]-k*A[2]))
        N=M
    elif len(l)==2:
        M=0
        for i in range(N//A[l[0]]+1):
            j=(N-i*A[l[0]])//A[l[1]]
            M=max(M,i*B[l[0]]+j*B[l[1]]+(N-i*A[l[0]]-j*A[l[1]]))
        N=M
    elif len(l)==1:
        i=N//A[l[0]]
        N=i*B[l[0]]+N-i*A[l[0]]
def b2(l):
    global N
    if len(l)==3:
        M=0
        for i in range(N//B[0]+1):
            for j in range((N-i*B[0])//B[1]+1):
                k=(N-i*B[0]-j*B[1])//B[2]
                M=max(M,i*A[0]+j*A[1]+k*A[2]+(N-i*B[0]-j*B[1]-k*B[2]))
                print(i,j,k,M)
        N=M
    elif len(l)==2:
        M=0
        for i in range(N//B[l[0]]+1):
            j=(N-i*B[l[0]])//B[l[1]]
            M=max(M,i*A[l[0]]+j*A[l[1]]+(N-i*B[l[0]]-j*B[l[1]]))
        N=M
    elif len(l)==1:
        i=N//B[l[0]]
        N=i*A[l[0]]+N-i*B[l[0]]
b(l1)
r=list(map(lambda x: -x,r))
b2(l2)
print(N)

Submission status: Wrong Answer

Solution code:
n= int(input())
gsb = [tuple(map(int,input().split())) for _ in range(2)]

def increase(num, gsb0, gsb1):
    dp = [ [0] * (num+1) for _ in range(3+1)]
    dp[0][0] = 0
    for i in range(1,4):
        w = gsb0[i-1]
        v = gsb1[i-1]
        for j in range(num+1):
            if(j < w):
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = max(dp[i-1][j], dp[i][j-w] + v)

    return(dp[-1][-1])

num = increase(n,gsb[0],gsb[1])
num = increase(num,gsb[1],gsb[0])

print(num)

Submission status: Wrong Answer

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

def rec1(n):
    if memo1[n]!=-1:
        return n
        
    res = n
    
    for a, b in [(ga, gb), (sa, sb), (ba, bb)]:
        if n-a>=0:
            res = max(res, rec1(n-a)+b)
    
    memo1[n] = res
    
    return res

def rec2(m):
    if memo2[m]!=-1:
        return m
        
    res = m
    
    for a, b in [(ga, gb), (sa, sb), (ba, bb)]:
        if m-b>=0:
            res = max(res, rec2(m-b)+a)
    
    memo2[m] = res

    return res

N = int(input())
ga, sa, ba = map(int, input().split())
gb, sb, bb = map(int, input().split())
memo1 = [-1]*(N+1)
M = rec1(N)
memo2 = [-1]*(M+1)

print(rec2(M))

Submission status: Wrong Answer

Solution code:
N = int(input())
ga, sa, ba = map(int, input().split())
gb, sb, bb = map(int, input().split())
ans = 0

for i in range(N+1):
    for j in range(N+1):
        if i+j>N:
            continue
        
        ans_cand = 0
        ans_cand += i//min(ga, gb)*max(ga, gb)+i%min(ga, gb)
        ans_cand += j//min(sa, sb)*max(sa, sb)+j%min(sa, sb)
        k = N-i-j
        ans_cand += k//min(ba, bb)*max(ba, bb)+k%min(ba, bb)
        ans = max(ans, ans_cand)

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
from itertools import accumulate

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = LIST()
B = LIST()

S1 = []
S2 = []
for i in range(3):
    if A[i] > B[i]:
        S1.append(i)
        A[i], B[i] = B[i], A[i]
    else:
        S2.append(i)

def calc(cnt, i):
    d, m = divmod(cnt, A[i])
    return d * B[i] + m

def count(S, N):
    if len(S) == 0:
        return N
    elif len(S) == 1:
        res = 0
        return calc(N, S[0])
    elif len(S) == 2:
        res = 0
        for x in range(N+1):
            y = N - x
            if y < 0:
                break
            cnt = calc(x, S[0]) + calc(y, S[1])
            res = max(res, cnt)
        return res
    else:
        res = 0
        for x in range(N+1):
            for y in range(N+1):
                z = N - x - y
                if z < 0:
                    break
                cnt = calc(x, S[0]) + calc(y, S[1]) + calc(z, S[2])
                res = max(res, cnt)
        return res

N2 = count(S1, N)
ans = count(S2, N2)
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
from itertools import accumulate

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
ga, sa, ba = MAP()
gb, sb, bb = MAP()

if ga > gb:
    ga, gb = gb, ga
if sa > sb:
    sa, sb = sb, sa
if ba > bb:
    ba, bb = bb, ba

ans = N
for x in range(N+1):
    for y in range(N+1):
        z = N - x - y
        if z < 0:
            break
        cnt = 0
        d, m = divmod(x, ga)
        cnt += d * gb + m
        d, m = divmod(y, sa)
        cnt += d * sb + m
        d, m = divmod(z, ba)
        cnt += d * bb + m
        ans = max(ans, cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
from itertools import accumulate

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
ga, sa, ba = MAP()
gb, sb, bb = MAP()

if ga > gb:
    ga, gb = gb, ga
if sa > sb:
    sa, sb = sb, sa
if ba > bb:
    ba, bb = bb, ba

ans = N
for x in range(N+1):
    for y in range(N+1):
        z = N - x - y
        if z < 0:
            continue
        cnt = 0
        d, m = divmod(x, ga)
        cnt += d * gb + m
        d, m = divmod(y, sa)
        cnt += d * sb + m
        d, m = divmod(z, ba)
        cnt += d * bb + m
        ans = max(ans, cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
from itertools import accumulate

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
ga, sa, ba = MAP()
gb, sb, bb = MAP()

if ga > gb:
    ga, gb = gb, ga
if sa > sb:
    sa, sb = sb, sa
if ba > bb:
    ba, bb = bb, ba

ans = N
for x in range(N+1):
    for y in range(N+1):
        z = N - x - y
        if z < 0:
            continue
        cnt = x // ga * gb + y // sa * sb + z // ba * bb
        ans = max(ans, cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
from itertools import accumulate

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
ga, sa, ba = MAP()
gb, sb, bb = MAP()

if ga > gb:
    ga, gb = gb, ga
if sa > sb:
    sa, sb = sb, sa
if ba > bb:
    ba, bb = bb, ba

ans = 0
for x in range(N+1):
    for y in range(N+1):
        z = N - x - y
        if z < 0:
            continue
        cnt = x // ga * gb + y // sa * sb + z // ba * bb
        ans = max(ans, cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
from itertools import accumulate

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
ga, sa, ba = MAP()
gb, sb, bb = MAP()

if ga > gb:
    ga, gb = gb, ba
if sa > sb:
    sa, sb = sb, sa
if ba > bb:
    ba, bb = bb, ba

ans = 0
for x in range(N+1):
    for y in range(N+1):
        z = N - x - y
        if z < 0:
            continue
        cnt = x // ga * gb + y // sa * sb + z // ba * bb
        ans = max(ans, cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
g1,s1,b1 = map(int,input().split())
g2,s2,b2 = map(int,input().split())
def trade(n,g1,s1,b1,g2,s2,b2):
  tradelist = []
  for x,y in (g1,g2),(s1,s2),(b1,b2):
    if x < y:
      tradelist.append((x,y))
  if not tradelist:
    return n
  dp = [0]*(n+1)
  for w,v in tradelist:
    for i in range(n+1-w):
      dp[i+w] = max(dp[i+w],dp[i]+v)
  return dp[n]

ans1 = trade(n,g1,s1,b1,g2,s2,b2)
ans2 = trade(ans1,g2,s2,b2,g1,s1,b1)
print(ans2)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d1 = []
d2 = []
for i in range(3):
  if a[i] < b[i]: d1.append((a[i], b[i]))
  if a[i] > b[i]: d2.append((b[i], a[i]))

dp = [0] * (N + 1)

for i in range(N, -1, -1):
  for t in d1:
    x = t[0]
    y = t[1]
    if i - x >= 0:
      dp[i - x] = max(dp[i - x], y + dp[i])
for i in range(N + 1): dp[i] += i

def calc(x, r1):
  z = r1 - d2[0][0] * x
  return (z // d2[1][0]) * d2[1][1] + z % d2[1][0] + d2[0][1] * x

res1 = max(dp)
if len(d2) == 0:
  print(res1)
if len(d2) == 1:
  x, y = d2.pop()
  print((res1 // x) * y + (res1 % x))
if len(d2) == 2:
  x0 = 0
  x1 = 0
  x2 = 0
  x3 = res1 // d2[0][0]
  while x3 - x0 > 2:
    x1 = (x0 * 2 + x3) // 3
    x2 = (x0 + x3 * 2) // 3

    c1 = calc(x1, res1)
    c2 = calc(x2, res1)
    if c1 < c2: x0 = x1
    else: x3 = x2
  res2 = 0
  for x in range(x0, x3 + 1):
    res2 = max(res2, calc(x, res1))
  print(res2)

if len(d2) == 3:
  dp2 = [0] * (res1 + 1)
  for i in range(res1, -1, -1):
    for t in d2:
      x = t[0]
      y = t[1]
      if i - x >= 0:
        dp2[i - x] = max(dp2[i - x], y + dp2[i])
  for i in range(res1 + 1): dp2[i] += i
  print(max(dp2))