#P2248. 分段

分段

Description

You are given nn numbers a1ana_1 \sim a_n, and you need to partition them into several contiguous segments, with the constraint that there are mm specified pairs of numbers that cannot be placed in the same segment.

The cost of creating one segment is:

K+S×(PQ)K + S \times (P - Q)

where KK and SS are given constants, PP is the maximum value in that segment, and QQ is the minimum value in that segment.

You need to find a partitioning scheme that minimizes the sum of costs over all segments.

Input Format

The first line contains two positive integers n,mn,m.

The second line contains two non-negative integers K,SK,S.

The third line contains nn non-negative integers a1ana_1 \sim a_n.

Each of the next mm lines contains 22 positive integers pi,qip_i,q_i, indicating that api,aqia_{p_i},a_{q_i} cannot be in the same segment.

Output Format

Output a single line containing the minimum possible sum of the costs over all segments.

5 2
3 1
2 3 12 14 16
2 3
3 1
11

Hint

For 10%10\% of the testdata, n10n \leq 10.

For 30%30\% of the testdata, n1500n \leq 1500.

For another 10%10\% of the testdata, S=0S = 0.

For another 30%30\% of the testdata, m=0m = 0.

For 100%100\% of the testdata, 1m,n1051 \le m,n \le 10^5, 0K,S,ai1050 \le K,S,a_i \le 10^5, 1pi,qin1 \le p_i,q_i \le n, piqip_i \ne q_i.

Translated by ChatGPT 5