LearnToCP
Sign in
Navigation
HomeRoadmapProblemsAbout Us
Theory
Contest Knowledge
Selecting an IDEInteractive TasksOutput-Only Tasks
Basics
Your First ProgramData types and IOC++ syntaxModuloFunctionsVectorsMatricesTime Complexity
Sorting
SortingCounting sortRadix Sort
Optimization Techniques
Two PointersSum of numbers 1 to nPrefix sumBinary SearchGreedyBinary Search FunctionsBinary Search by AnswerDivide and Conquer
Binary Numbers
Binary NumbersNumbers in codeBitwise OperationsBitmasks
Math
Binary ExponentiationPrime NumbersPrime FactorizationGCD and LCMSieve of EratosthenesModified Sieve
Data Structures
StringsStackQueueMapsSetsPriority QueueCustom Criteria for FunctionsSegment TreesFenwick TreesSparse TablesUnion FindSqrt Decomposition
Combinatorics
Addition PrincipleMultiplication PrincipleCombinatoric ObjectsInclusion Exclusion Principle
Geometry
Geometry BasicsVectorsCross and Dot ProductLinesPolygonsAnglesPoint in PolygonDistances and Intersection PointsConvex HullCircles
Recursion
PointersRecursionGenerating Combinatoric Objects
Dynamic Programming
About DPDP problemsTree DPBitmask DP
Graph Theory
GraphsDFS and BFSShortest PathsTreesTopological SortingDijkstra's AlgorithmMinimum Spanning TreesShortest Path Algorithms
Advanced Graph Theory
BiconnectivityStrongly Connected ComponentsBipartite GraphGraph FlowAugmenting PathsFlow - Minimum Cut DualityHeavy-Light DecompositionCentroid Decomposition
Advanced Data Structures
2D and 3D Segment TreesLazy PropagationImplicit Segment TreesPersistent Segment TreesLowest Common AncestorTrieBalanced Binary Search TreesMo's Algorithm

Woodcutter

EasyProblem #57
Time LimitMemoryInputOutput
1 s64 MBstdinstdout

Once the saw is too high to give enough wood, raising it further will not help either.

Milan the woodcutter has to bring home a certain amount of wood. His saw sits on a stand that can be set to any integer height in meters, and it cuts every tree in the forest at exactly that height. Only the part of a tree above the blade falls down - a tree that is not taller than the blade is left untouched.

The higher the saw stands, the less wood Milan gets. He cares about the forest, so he does not want to cut a single meter more than he needs.

All trunks are equally thick, so the amount of wood is simply measured in meters of cut trunk. Your task is to find the highest integer height at which Milan can set the saw and still get at least the amount of wood he needs.

Input

First line of input will be a single integer t - the number of testcases.
The first line of each testcase contains two integers n and x - the number of trees in the forest and the amount of wood Milan needs.
The second line contains n integers h1​,h2​,…,hn​ - the heights of the trees.

Output

For every testcase print a single line with the highest height at which the saw can be set.

Example

Input
2
5 14
24 21 19 14 22
1 7
7
Output
18
0

In the first testcase the saw set to 18 meters takes 6 meters off the first tree, 3 off the second, 1 off the third, nothing off the fourth and 4 off the fifth - exactly the 14 meters Milan needs. In the second testcase the only tree has to be cut all the way to the ground.

Constraints

1≤t≤10
1≤n≤105
1≤hi​≤104
1≤x≤h1​+h2​+⋯+hn​ - there is always enough wood in the forest


This problem was adapted, with permission, from Drva, authored by Društvo matematičara Srbije and Fondacija Petlja.

Submit your solution

Sign in to submit your solution and track your progress.

Sign in to submit