A good array
Practice
4 (9 votes)
Greedy algorithms
Algorithms
Basics of greedy algorithms
Greedy algorithm
Problem
53% Success 2282 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You are given an array
Good array: In a good array, select any subarray of even length
In order to transform an array to good array, you can perform the following two operations as many times as you want:
- Choose any index
and if it is currently 0, then convert it to 1 for X coins. - Choose any index
and if it is currently 1, then convert it to 0 for Y coins.
Your task is to minimize the cost of transformation of an array to good array.
Input format
- The first line contains
denoting the number of test cases. - The first line of each test case contains three space-separated integers
, , and . - The second line of each test case consists of
space-separated integers of array .
Output format
For each test case, print one line denoting the minimum cost to transform array
Constraints
Please login to use the editor
You need to be logged in to access the code editor
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
4 votes
Tags:
Basics of Greedy AlgorithmsAlgorithmsGreedy Algorithms
Points:20
8 votes
Tags:
Greedy AlgorithmsBasics of Greedy AlgorithmsAlgorithms
Points:20
43 votes
Tags:
AlgorithmsEasyGreedy Algorithms
Editorial
Login to unlock the editorial