Problem Description
Description
LT was not convinced by the previous problem and said such a simple problem was beneath him, so we decided to make the problem harder. The following is the problem set by our LT: Suppose you are given a sequence of n numbers A1, A2, A3, A4 … An. You can choose an interval of any size and replace every number x in it with (x*1888+101)%14507. What is the maximum possible sum of these n numbers?
Input
There are multiple test cases. For each test case, the first line contains an integer n, the number of elements in the sequence. (1 <= n <= 100000) The second line contains n integers A1, A2, A3, A4 … An. (0 <= Ai <= 10000)
Output
For each test case, output one line with the answer.
Sample Input
| |
Sample Output
| |
HINT
The range is within int.
Problem Analysis
This problem can be transformed into finding the maximum subarray sum.
Because if no values are changed, the result is the sum of a1~n.
If we compute the difference between (x*1888+101)%14507 and x for each number,
changing the values in an interval can be represented as selecting a subarray.
To maximize the final result, it is obvious that the sum of the selected subarray should be as large as possible.
So solve it with DP, complexity O(n).
| |
Problem link: ZZULI 1837 LT Refuses to Accept It