32 lines
656 B
Python
32 lines
656 B
Python
n = int(input())
|
|
prices = list(map(int, input().split()))
|
|
|
|
dp = [0] * (n + 1)
|
|
choice = [0] * (n + 1)
|
|
|
|
for i in range(1, n + 1):
|
|
max_revenue = prices[i - 1]
|
|
best_cut = 0
|
|
|
|
for j in range(1, i):
|
|
revenue = prices[j - 1] + dp[i - j]
|
|
if revenue > max_revenue:
|
|
max_revenue = revenue
|
|
best_cut = j
|
|
|
|
dp[i] = max_revenue
|
|
choice[i] = best_cut
|
|
|
|
pieces = []
|
|
remaining = n
|
|
while remaining > 0:
|
|
cut = choice[remaining]
|
|
if cut == 0:
|
|
pieces.append(remaining)
|
|
remaining = 0
|
|
else:
|
|
pieces.append(cut)
|
|
remaining -= cut
|
|
|
|
print(dp[n])
|
|
print(' '.join(map(str, pieces))) |