#P5336. [THUSC 2016] 成绩单

[THUSC 2016] 成绩单

Problem Description

The final exams are over. Head teacher Mr. L needs to hand out the report cards to every student. Mr. L has nn report cards, stacked on the desk in order from 11 to nn, where the score on report card ii is WiW_i.

The report cards are handed out in batches. When handing them out, Mr. L will take a consecutive segment from the current stack of report cards, and the students in that segment come to pick up their own report cards. After this batch of students finishes, Mr. L then takes another consecutive segment from the remaining report cards for the next batch. After several batches, all report cards will be handed out.

However, handing out report cards is a headache. On one hand, he needs to take care of the students' feelings, so students with scores that differ too much should not pick up their report cards in the same batch. On the other hand, he must consider the time cost and try to reduce the number of batches.

For a distribution plan, we define its cost as:

$$a \times k + b \times \sum_{i = 1} ^ k (max_i - min_i) ^ 2$$

where kk is the number of batches. For the report cards handed out in the ii-th batch, maximax_i is the highest score and minimin_i is the lowest score. aa and bb are given evaluation parameters. Now, please help Mr. L find the plan with the minimum cost, and report this minimum cost to Mr. L. Of course, the number of batches kk is up to you.

Input Format

The first line contains a positive integer nn, indicating the number of report cards. The second line contains two non-negative integers a,ba, b, indicating the given evaluation parameters. The third line contains nn positive integers wiw_i, where wiw_i is the score on the ii-th report card.

Output Format

Output a single positive integer, indicating the minimum cost.

10
3 1
7 10 9 10 6 7 10 7 1 2

15

Hint

Constraints: n50n \leq 50a1500a \leq 1500b10b \leq 10wi1000w_i \leq 1000

Translated by ChatGPT 5