Alice in the Digital World
Time limit1sMemory limit512 MB
Find the maximum sum over subarrays whose minimum element equals m, given that the array and m are bounded by 26.
- Level
Medium6 of 10
- Topics
- Array, Divide and conquer, Prefix sum, Greedy
- Solved
- No attempts yet
Problem
After returning from Wonderland, Alice needs to improve her scientific skills in this digital world. Alice decides to take part in the ACM-ICPC Asia Nha Trang Regional Contest 2016 to evaluate her actual performance. Her favorite problem in the contest is the following.
Given an array of positive integers , a subarray of is a sequence of continuous elements in , that is, (where ). The weight of is the sum of all its elements.
Given an integer , your task is to find the maximum weight subarray of that contains exactly one as the minimum element. You can assume that always contains at least one element with value .
Input
The input consists of several datasets. The first line of the input contains the number of datasets, which is a positive number and is not greater than 20. The following lines describe the datasets.
Each dataset is described by the following lines:
- The first line contains 2 positive integers and (; ).
- The second line contains positive integers, each with value at most 26.
Output
For each dataset, write out on one line the found maximum weight.