Problem: Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).  Consider a sequence A satisfying the following conditions:    * A is a sequence of N positive integers.   * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.  Let us define a score of this sequence as follows:    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)  Find the maximum possible score of A.

Submission attempts (in order):
a, b, n = map(int, input().split())
ans = 0
s = max(int(b/a),e-1000)
e = min(n+1,b)
for i in range(s, e):
  x = (int(a*i/b)-a*int(i/b))
  if ans < x:
    ans = x
print(ans)

n, m, q = map(int, input().split())
a = [0]*q
b = [0]*q
c = [0]*q
d = [0]*q
for i in range(q):
  a[i], b[i], c[i], d[i] = map(int, input().split())
A = [1] * 10

def check(A, ans):
  t = 0
  for i in range(q):
    if A[b[i]] - A[a[i]] == c[i]:
      t += d[i]
  if ans < t:
    return t
  else:
    return ans

ans = 0
for i1 in range(1, m):
  A[1] = i1
  for i2 in range(i1, m):
    A[2] = i2
    for i3 in range(i2, m):
      A[3] = i3
      for i4 in range(i3, m):
        A[4] = i4
        for i5 in range(i4, m):
          A[5] = i5
          for i6 in range(i5, m):
            A[6] = i6
            for i7 in range(i6, m):
              A[7] = i7
              for i8 in range(i7, m):
                A[8] = i8
                for i9 in range(i8, m):
                  A[9] = i9
                  ans = check(A, ans)
print(ans)

n, m, q = map(int, input().split())
a = [0]*q
b = [0]*q
c = [0]*q
d = [0]*q
for i in range(q):
  a[i], b[i], c[i], d[i] = map(int, input().split())
A = [1] * 10

def check(A, ans):
  t = 0
  for i in range(q):
    if A[b[i]] - A[a[i]] == c[i]:
      t += d[i]
  if ans < t:
    return t
  else:
    return ans

ans = 0
for i1 in range(1, m):
  A[1] = i1
  for i2 in range(i1, m):
    A[2] = i2
    for i3 in range(i2, m):
      A[3] = i3
      for i4 in range(i3, m):
        A[4] = i4
        for i5 in range(i4, m):
          A[5] = i5
          for i6 in range(i5, m):
            A[6] = i6
            for i7 in range(i6, m):
              A[7] = i7
              for i8 in range(i7, m):
                A[8] = i8
                for i9 in range(i8, m):
                  A[9] = i9
                  ans = check(A, ans)
print(ans)

n, m, q = map(int, input().split())
a = [0]*q
b = [0]*q
c = [0]*q
d = [0]*q
for i in range(q):
  a[i], b[i], c[i], d[i] = map(int, input().split())
A = [1] * 10

def check(A, ans):
  t = 0
  for i in range(q):
    if A[b[i]-1] - A[a[i]-1] == c[i]:
      t += d[i]
  if ans < t:
    return t
  else:
    return ans

ans = 0
for i1 in range(1, m):
  A[1] = i1
  if n >= 3:
    for i2 in range(i1, m):
      A[2] = i2
      if n >= 4:
        for i3 in range(i2, m):
          A[3] = i3
          if n >= 5:
            for i4 in range(i3, m):
              A[4] = i4
              if n >= 6:
                for i5 in range(i4, m):
                  A[5] = i5
                  if n >= 7:
                    for i6 in range(i5, m):
                      A[6] = i6
                      if n >= 8:
                        for i7 in range(i6, m):
                          A[7] = i7
                          if n >= 9:
                            for i8 in range(i7, m):
                              A[8] = i8
                              if n >= 10:
                                for i9 in range(i8, m):
                                  A[9] = i9
                                  ans = check(A, ans)
                              else:
                                ans = check(A, ans)
                          else:
                            ans = check(A, ans)
                      else:
                        ans = check(A, ans)
                  else:
                    ans = check(A, ans)
              else:
                ans = check(A, ans)
          else:
            ans = check(A, ans)
      else:
        ans = check(A, ans)
  else:
    ans = check(A, ans)
print(ans)

n, m, q = map(int, input().split())
a, b, c, d = [0]*q, [0]*q, [0]*q, [0]*q
for i in range(q): a[i], b[i], c[i], d[i] = map(int, input().split())
A = [1] * 10
 
def check(A, ans):
  t = 0
  for i in range(q):
    if A[b[i]-1] - A[a[i]-1] == c[i]:
      t += d[i]
  if ans < t: return t
  else: return ans
 
ans = 0
for i1 in range(1, m+1):
  A[1] = i1
  for i2 in range(i1, m+1):
    A[2] = i2
    for i3 in range(i2, m+1):
      A[3] = i3
      for i4 in range(i3, m+1):
        A[4] = i4
        for i5 in range(i4, m+1):
          A[5] = i5
          for i6 in range(i5, m+1):
            A[6] = i6
            for i7 in range(i6, m+1):
              A[7] = i7
              for i8 in range(i7, m+1):
                A[8] = i8
                for i9 in range(i8, m+1):
                  A[9] = i9
                  ans = check(A, ans)
print(ans)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Accepted