Problem list
Log in
#r03242 · Online Judge > GoldOJ

Budget

Silver II 2.0 s 1024 MB

Given $N$ budget requests and a total budget cap, allocate as much as possible: if all requests fit, grant them fully; otherwise pick an integer ceiling $c$ so that any request above $c$ receives exactly $c$ and the rest receive their full request, maximizing the total allocated without exceeding the cap. Print the maximum such ceiling (or the largest request if all fit).

Input

Line 1: $N$. Line 2: the $N$ requests. Line 3: the total budget.

Output

Print the maximum ceiling value.

Example 1

Input
4
120 110 140 150
485
Output
127

Example 2

Input
5
70 80 30 40 100
450
Output
100
Source
Online Judge > GoldOJ
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code