Alice is at the Mad Hatter's tea party! There is a long sheet cake made up of n sections…
- User
Alice is at the Mad Hatter's tea party! There is a long sheet cake made up of n sections with tastiness values a1,a2,…,an . There are m creatures at the tea party, excluding Alice.
Alice will cut the cake into m+1 pieces. Formally, she will partition the cake into m+1 subarrays, where each subarray consists of some number of adjacent sections. The tastiness of a piece is the sum of tastiness of its sections. Afterwards, she will divvy these m+1 pieces up among the m creatures and herself (her piece can be empty). However, each of the m creatures will only be happy when the tastiness of its piece is v or more.
Alice wants to make sure every creature is happy. Limited by this condition, she also wants to maximize the tastiness of her own piece. Can you help Alice find the maximum tastiness her piece can have? If there is no way to make sure every creature is happy, output −1 .
Input Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104 ). The description of the test cases follows.
The first line of each test case contains three integers n,m,v (1≤m≤n≤2⋅105 ; 1≤v≤109 ) — the number of sections, the number of creatures, and the creatures' minimum requirement for tastiness, respectively.
The next line contains n space separated integers a1,a2,…,an (1≤ai≤109 ) — the tastinesses of the sections.
The sum of n over all test cases does not exceed 2⋅105 .
Output For each test case, output the maximum tastiness Alice can achieve for her piece, or −1 if there is no way to make sure every creature is happy.
Example InputCopy 7 6 2 1 1 1 10 1 1 10 6 2 2 1 1 10 1 1 10 6 2 3 1 1 10 1 1 10 6 2 10 1 1 10 1 1 10 6 2 11 1 1 10 1 1 10 6 2 12 1 1 10 1 1 10 6 2 12 1 1 1 1 10 10 OutputCopy 22 12 2 2 2 0 -1 Note For the first test case, Alice can give the first and second section as their own pieces, and then take the remaining 10+1+1+10=22 tastiness for herself. We can show that she cannot do any better.
For the second test case, Alice could give the first and second section as one piece, and the sixth section as one piece. She can then take the remaining 10+1+1=12 tastiness for herself. We can show that she cannot do any better.
For the seventh test case, Alice cannot give each creature a piece of at least 12 tastiness. type code in c++
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.