#P8927. 「GMOI R1-T4」Rain

「GMOI R1-T4」Rain

Background

Praying for Rain

Grandpa Jade Emperor is also surnamed Zhang,

so why are you making things hard for my Zhang *Chang?

If it does not rain within three days,

first I will tear down the Dragon King Temple,

then I will use cannons to blow up your mother.

If it still does not rain, Marshal Zhang will blow up all religious sites across Asia!

Because Hakurei Shrine can be seen from the outside world, it naturally cannot escape this either. Reimu is very anxious and plans to use her ancestral secret technique to pray for rain...

Problem Description

To prevent the shrine from being "blasted by cannons", Reimu needs to pray for rain.

To pray for rain, she needs to build nn magic circles on a straight road, numbered 1,2,,n1,2,\cdots,n.

You are given an array aa of length nn, meaning that the magic circles are built at positions a1a_1 to ana_n. What you need to do is assign the numbers to the magic circles.

Reimu needs to test the effect of the circles. She will walk from circle 11 to circle 22, from 22 to 33, and so on until she reaches circle nn, then walk back from circle nn to circle 11.

Due to the special effect of the circles, the distance from the ii-th to the (i+1)(i+1)-th is ai×pai+1×q\left|a_i\times p-a_{i+1}\times q\right|. In particular, the distance from circle nn back to circle 11 is an×pa1×q\left|a_n\times p-a_1\times q\right|. Here p,qp,q are two given constants, and ai,ai+1a_i,a_{i+1} are the positions of the two circles.

Reimu wants you to find the maximum walking distance, and output a corresponding arrangement of the positions of circles numbered from 11 to nn. (If there are multiple answers, output any one.)

Input Format

The first line contains an integer nn, representing the number of magic circles.

The second line contains two integers p,qp,q, representing the multiplier constants.

The third line contains nn integers, representing the array aa.

Output Format

The first line contains one integer, representing the answer.

The second line contains nn integers, representing a permutation of the positions aa, output in order from circle 11 to circle nn.

10
2 3
1 2 3 4 5 6 7 8 9 10
131
5 6 7 1 8 2 9 3 10 4

Hint

This problem uses SPJ.

The input size is large; it is recommended to use faster input methods.

For 100%100\% of the testdata, 10n10610\le n\le 10^6, 1p,q1051\le p,q \le 10^{5}, 1ai1051\le a_i\le 10^{5}.

ID nn p,qp,q aia_i Score
11 n=10n=10 p,q103p,q\le 10^{3} ai103a_i\le 10^{3} 44
22 55
33
464\sim 6 n=19n=19 p,q105p,q\le 10^{5} ai105a_i\le 10^{5} 1010
77 n104n\le 10^{4} 88
88 99
99
101210\sim 12 n106n\le 10^{6} 1010

Translated by ChatGPT 5