Oracle
Time limit3sMemory limit256 MB
Given multipliers p_i and bet sizes j^2+aj+b for the j-th entered game, she picks a subsequence of exactly k games to maximize total profit, for every k.
- Level
Hard9 of 10
- Topics
- Dynamic programming, Divide and conquer, Greedy, Math
- Solved
- No attempts yet
Problem
In computing theory, an oracle is a black box that solves some problem in a single operation, and it is a tool for studying decision problems. The word comes from ancient Greece. The best known oracle is Pythia, the priestess of Apollo who delivered the oracles of Delphi. Pythia is not one person's name but the title given to the priestess in charge of the Delphic oracle, and Greeks consulted Delphi from the 7th century BC to the 4th century AD. The character of this problem is Phemonoe, the first Pythia of Delphi, said by some to be a daughter of Apollo herself.
Phemonoe faces games in order. Game 1 through game take place one after another, and she cannot go back to a game that is already finished, because turning back time is outside Apollo's powers. She may skip any game she does not like. In a game she enters she places a bet and receives her bet multiplied by that game's multiplier. A negative multiplier means she loses that much. Normally nobody knows the results in advance, but Apollo told Phemonoe every result because she is the oracle of Delphi. He did warn her not to be greedy. Winning too much draws suspicion, and Apollo would be in trouble if Zeus found out. The trouble is that after a few glasses of good Greek wine her judgment is not what it should be. Her confidence grows and so do her bets: on the -th game she enters she bets exactly . As her adviser, your job is to maximize her profit. She will not listen to you about how many games she plays or how much she bets, but she will follow your advice about which games to enter.
Let be the multiplier of the -th game. If Phemonoe enters the games , her profit is . For each , find the maximum profit she can make by entering exactly games.
Input
The first line contains the number of test cases ().
The first line of each test case contains the number of games (). The second line contains integers () separated by spaces, where is the multiplier of the -th game. The third line contains two non-negative integers and (, , ). Phemonoe bets on the -th game she enters.
Output
For each test case, print integers on one line, separated by single spaces. The -th number is the maximum profit she can make by entering exactly games.