This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
def max_points(n, k, arr):
dp = [[0 for _ in range(n+1)] for _ in range(k+1)]
pref = [0 for _ in range(n+1)]
track = [[0 for _ in range(n+1)] for _ in range(k+1)]
for i in range(1, n+1):
pref[i] = pref[i-1] + arr[i-1]
for i in range(1, n+1):
dp[1][i] = pref[i]*pref[n] - pref[i]*pref[i-1]
track[1][i] = 0
for i in range(2, k+1):
mx = [(dp[i-1][j] + pref[j]*pref[i-1] - pref[j]*pref[j-1], j) for j in range(i-1)]
for j in range(i, n+1):
mx[0] = max(mx[0], (dp[i-1][j-1] + pref[j-1]*pref[n] - pref[j-1]*pref[j-2], j-1))
dp[i][j], track[i][j] = mx[0]
res = [0]*k
cur = n
for i in range(k, 0, -1):
res[i-1] = track[i][cur]
cur = res[i-1]
return dp[k][n], res
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |