#P16304. [蓝桥杯 2026 省 Java C 组] 抽奖活动

    ID: 18319 远端评测题 3000ms 512MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>2026蓝桥杯省赛状压 DP

[蓝桥杯 2026 省 Java C 组] 抽奖活动

Problem Description

When Xiao Lan was shopping, he encountered a lottery event.

At the beginning, there are nn balls arranged in a row from left to right. The ii-th ball has an integer aia_i written on it.

Xiao Lan bought kk lottery chances in total. In each lottery, he can choose one ball from the remaining balls and take it away, but only balls that satisfy the following conditions can be taken:

Suppose this ball is currently the ii-th ball from left to right among the remaining balls. Let:

  • LiL_i be the number of remaining balls to the left of this ball.
  • RiR_i be the number of remaining balls to the right of this ball.

Then this ball must satisfy both:

  • Ri>0R_i > 0.
  • LiL_i is an integer multiple of RiR_i (in particular, 00 is considered an integer multiple of any non-zero integer).

After taking a ball each time, the remaining balls will be rearranged into a row while keeping their original relative order.

Xiao Lan can perform at most kk lotteries, and he may also perform fewer than kk times. Please compute the maximum possible sum of the integers on the balls he can take.

Input Format

The input has two lines.

The first line contains two positive integers n,kn, k.

The second line contains nn positive integers a1,a2,…,ana_1, a_2, \dots, a_n, representing the integer on each ball.

Output Format

Output one line with one integer, representing the maximum sum of integers Xiao Lan can obtain after at most kk lotteries.

7 2
2 8 2 4 2 6 3
10

Hint

Sample Explanation

One feasible plan is:

  • In the first time, take the current 44-th ball and get 44.
  • The remaining balls become 2,8,2,2,6,32, 8, 2, 2, 6, 3.
  • In the second time, take the current 55-th ball and get 66.

The total sum is 4+6=104 + 6 = 10.

Another feasible plan is:

  • In the first time, take the current 11-st ball and get 22.
  • The remaining balls become 8,2,4,2,6,38, 2, 4, 2, 6, 3.
  • In the second time, take the current 11-st ball again and get 88.

The total sum is also 2+8=102 + 8 = 10.

Constraints

For 100%100\% of the data, it is guaranteed that 1≤k≤n≤201 \le k \le n \le 20 and 1≤ai≤1001 \le a_i \le 100.

Translated by ChatGPT 5