PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000355. Nâng cấp kỹ năng (Skills)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Nâng cấp kỹ năng (Skills)

Skills

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Lesha is playing a new version of hacknet. His character has nn skills, numbered from 11 to nn. Skill ii starts at level aia_i, and all skills share the maximum level AA.

The ranking uses a strength value. For final levels b1,b2,…,bnb_1,b_2,\ldots,b_n, this value is

$$F=c_f\cdot |\{i:b_i=A\}|+c_m\cdot\min_{1\le i\le n}b_i.$$

The nonnegative coefficients cf,cmc_f,c_m reward the number of fully upgraded skills and the lowest skill level, respectively.

Lesha has mm currency units. One unit raises any chosen skill by 11 provided it is below AA. Spending the entire budget is optional.

Find the highest attainable strength and one corresponding sequence of final levels.

Input

The first line contains five integers n,A,cf,cm,mn,A,c_f,c_m,m: the number of skills, the maximum level, the two strength coefficients and the available budget.

The second line contains exactly nn integers a1,a2,…,ana_1,a_2,\ldots,a_n, the initial levels in skill order.

Output

Print the maximum strength on the first line.

On the second line print nn integers b1,b2,…,bnb_1,b_2,\ldots,b_n in skill order, satisfying ai≤bi≤Aa_i\le b_i\le A for every 1≤i≤n1\le i\le n and ∑i=1n(bi−ai)≤m\sum_{i=1}^n(b_i-a_i)\le m. Their strength must equal the value on the first line. Any optimal sequence is accepted.

Subtasks

  • Subtask 1 (20 points): 1≤n≤71\le n\le 7; 1≤A≤81\le A\le 8; 0≤cf,cm≤10000\le c_f,c_m\le 1000; 0≤m≤400\le m\le 40; 0≤ai≤A0\le a_i\le A for every 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le 2000; 1≤A≤10001\le A\le 1000; 0≤cf,cm≤10000\le c_f,c_m\le 1000; 0≤m≤10000000\le m\le 1000000; 0≤ai≤A0\le a_i\le A for every 1≤i≤n1\le i\le n.
  • Subtask 3 (50 points): 1≤n≤1000001\le n\le 100000; 1≤A≤10000000001\le A\le 1000000000; 0≤cf,cm≤10000\le c_f,c_m\le 1000; 0≤m≤10000000000000000\le m\le 1000000000000000; 0≤ai≤A0\le a_i\le A for every 1≤i≤n1\le i\le n.

Examples

Input 1

3 5 10 1 5
1 3 1

Output 1

12
2 5 2

Explanation

Raise the second skill from 33 to 55 for 22 units and each other skill from 11 to 22 for another 22. Strength is 10⋅1+1⋅2=1210\cdot1+1\cdot2=12. Two perfect skills cost at least 66. With one perfect skill, reaching minimum 33 costs at least 66. With no perfect skills the strength is at most 55.

Input 2

3 5 10 1 339
1 3 1

Output 2

35
5 5 5

Explanation

Making every skill level 55 costs 4+2+4=104+2+4=10, within 339339. Strength is 10⋅3+1⋅5=3510\cdot3+1\cdot5=35, the upper bound since there are only three skills and the minimum level cannot exceed 55.