#P10412. 「QFOI R2」钟声远带斜阳

    ID: 11699 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>贪心洛谷原创O2优化前缀和差分洛谷月赛

「QFOI R2」钟声远带斜阳

Problem Description

Note: In this problem, all sequence indices start from 00.

Little R is a lovely girl who likes studying infinite sequences.

She calls an infinite sequence bb wonderful if and only if there exists a natural number k0k_0 such that for all kk0k \ge k_0, the sum of all numbers in bb with indices in the interval [k0,k][k_0, k] is non-negative (that is, i=k0kbi0\sum_{i=k_0}^k b_i \ge 0). For example, the sequence αi=i5\alpha_i = i - 5 is wonderful, taking k0=5k_0 = 5 works; but βi=i\beta_i = -i is not wonderful.

She currently only has a finite sequence aa of length nn, and she can perform the following three operations any number of times:

  1. Pay cost pp, choose an integer ii (0i<n0 \le i < n), and increase aia_i by 11.
  2. Pay cost qq, choose an integer ii (0i<n0 \le i < n), delete aia_i, and update nn to be the new length of the sequence. You cannot delete the sequence until it becomes empty.
  3. Pay cost rr, choose two integers i,ji, j (0i<j<n0 \le i < j < n), and swap aia_i and aja_j.

She hopes that after some operations, by concatenating infinitely many copies of the finite sequence aa in order, she obtains an infinite sequence bb (i.e., bi=aimodnb_i = a_{i \bmod n}), such that bb is wonderful. Please find the minimum total cost.

Input Format

The first line contains four integers n,p,q,rn, p, q, r.

The second line contains nn integers, representing the sequence aa.

Output Format

One line with one integer, representing the minimum cost.

5 1 2 5
2 -2 3 -3 -1
1
5 2 1 5
2 -2 3 -3 -1
1
5 1 1 1
0 1 2 3 4
0

Hint

Explanation of Sample 11

Pay cost p=1p = 1 to increase a3a_3 by 11, obtaining the sequence b=[2,2,3,2,1,2,2,3,2,1,]b = [2, -2, 3, -2, -1, 2, -2, 3, -2, -1, \cdots], which is wonderful. Taking k0=2k_0 = 2 satisfies the requirement.

It can be proven that no solution with a smaller cost exists.


Explanation of Sample 22

Pay cost q=1q = 1 to delete a1a_1, obtaining the sequence b=[2,3,3,1,2,3,3,1,]b = [2, 3, -3, -1, 2, 3, -3, -1, \cdots], which is wonderful. Taking k0=0k_0 = 0 satisfies the requirement.

It can be proven that no solution with a smaller cost exists.


Constraints

This problem uses bundled testdata. Only by passing all test points of a subtask and all the subtasks it depends on can you get the corresponding score.

For all testdata: 1n1051 \le n \le 10^5, 1p,q,r1091 \le p, q, r \le 10^9, ai109|a_i| \le 10^9.

  • Subtask 1 (1010 points): n=1n = 1.
  • Subtask 2 (1010 points): n10n \le 10. Depends on Subtask 1.
  • Subtask 3 (2020 points): ai1|a_i| \le 1.
  • Subtask 4 (2020 points): ai105\sum |a_i| \le 10^5. Depends on Subtask 3.
  • Subtask 5 (4040 points): No special restrictions. Depends on Subtasks 1, 2, 3, and 4.

Translated by ChatGPT 5