[Solution] Price Maximization Codeforces Solution
A batch of goods ( — an even number) is brought to the store, -th of which has weight . Before selling the goods, they must be packed into packages. After packing, the following will be done:
- There will be packages, each package contains exactly two goods;
- The weight of the package that contains goods with indices and () is .
With this, the cost of a package of weight is always burles (rounded down), where — a fixed and given value.
Solution Click Below:- CLICK HERE
Pack the goods to the packages so that the revenue from their sale is maximized. In other words, make such pairs of given goods that the sum of the values , where is the weight of the package number (), is maximal.
For example, let , weights of goods . Let's pack them into the following packages.
- In the first package we will put the third and sixth goods. Its weight will be . The cost of the package will be burles.
- In the second package put the first and fifth goods, the weight is . The cost of the package is burles.
- In the third package put the second and fourth goods, the weight is . The cost of the package is burle.
With this packing, the total cost of all packs would be burles.
The first line of the input contains an integer () —the number of test cases in the test.
The descriptions of the test cases follow.
The first line of each test case contains two integers () and (). The number — is even.
The second line of each test case contains exactly integers ().
It is guaranteed that the sum of over all the test cases does not exceed .
For each test case, print on a separate line a single number — the maximum possible total cost of all the packages.
No comments:
Post a Comment