6
1
Hey guys, first time poster here. I went on Coderoulette recently and some guy posted this question. I looked around online but it doesn't seem to be anywhere. I figured I would post it here for anyone who is a fan of these types of problems. Enjoy!
Alexa is a druid who loves Mathematics! She lives in the land of Alfa, taking care of a tea plantation.
The plantation has N plants and the height of the ith plant is Hi.
Alexa has developed a recent interest in palindromes. She wants to crop the plants so the height of the plants forms a palindrome (without any reordering). She has 2 spells in her arsenal- the 'Growlith' spell will increase the height of a plant by 1 unit, the 'Shrinkooza' spell will decrease the height of a plant by 1 unit. The 'Growlith' and 'Shrinkooza' spells cost A and B units of magic respectively. Help Alexa find the minimum units of magic, that shall enable her to fulfill her objective.
Input Format
First line contains an integer T. T testcases follow.
First line of each test case consists of 3 space-separated integers N, A and B.
Next line consists of N space-separated integers, the initial height of the plants.
Output Format
Print the answer to each test case on a new line.
Constraints
1 <= T <= 10
1 <= N <= 105
0 <= A, B <= 108
1 <= Hi <= 103
Example
Input
1
5 2 2
1 6 2 3 4
Output
12
Explanation
She can use the 'Growlith' spell on the first plant 3 times and the 'Shrinkooza' spell on the second plant 3 times to form 4 3 2 3 4.
Challenge
Write code that will create a palindrome using the least units of magic possible for N plants.
Scoring
This is code golf. The shortest code in bytes wins.
3What's the winning criterion? – acrolith – 2016-09-21T18:07:06.607
1Don't be discouraged just check out some other challenges based on their input format and winning criterion, the underlying problem is interesting. – ThreeFx – 2016-09-21T18:15:28.747
5
Also, @AlexA. is male.
– flawr – 2016-09-21T18:16:38.417"Lowest complexity" for this is probably not ideal, since there's an easy O(n) solution that will probably be used by all answers. – Geobits – 2016-09-21T18:32:00.177
I'm open to suggestions. I just think it's an interesting problem and wasn't sure where else to post it. If you have a better winning criterion please feel free to edit or let me know! – twoTimesAgnew – 2016-09-21T18:33:48.213
1Code golf (e.g shortest answer wins) is usually the easiest one. – James – 2016-09-21T18:35:52.313
4
Please reconsider the input format. Usually we are not so restrictive. People want to use the native format of their favorite language. "Any reasonable format" is a good way to go.
– nimi – 2016-09-21T19:51:05.5371I don't see the need for multiple testcases in a single run (that's more for automation on another sites). Welcome to PPCG. – Linus – 2016-09-22T05:15:01.093
The introduction makes me worry that this might be a copyright infringement. Was the original question posted under a licence compatible with CC-SA? – Peter Taylor – 2016-09-22T07:26:21.117
2Maybe I am missing something or your provided output example and the challenge do not match exactly. do you want the minimal cost to create a palindrome or the palindrome itself? (or both?) – nyro_0 – 2016-09-22T08:17:27.767