149. [usaco dec07] Bookshelf 2
★Input file:Shelf2.in
Output file:Shelf2.out
Simple comparison
Time Limit: 1 s memory limit: 128 MB
Translated by cmykrgb123
Farmer John recently bought a shelf for the dairy library, and the bottom of the shelf soon filled with books. Now there is only space on the top shelf.
In the N (1 ≤ n ≤ 20) Head ox, the height of the I head ox is hi (1 ≤ Hi ≤ 1,000,000 ). The shelving height is B (1 ≤ B ≤ 2,000,000,007), and B is less than the sum of the heights of all cows.
The top of the shelf is higher than the height of the highest ox, but several cows can stand in one stack, so the total height is the sum of their heights. The total height should be greater than or equal to the height of the bookshelf before the cows can get the books.
But the more cows stand together, the more dangerous they are. Your job is to find the minimum height in which the total height of the cow exceeds the shelf height.
Input
- Row 1st: two integers: N, B
- 2nd. n + 1 row: line I + 1 contains an integer hi
Output
- Row 1st: a non-negative integer. the total height of the cow exceeds the minimum height of the bookshelf.
Sample Input
5 1631356
Sample output
1
Simple search
# include
using namespace STD; int A [22]; int ans, N, B; void DFS (INT cur, int num) {If (Num> = B & num-B> ans) return; If (cur = n + 1) {If (Num> = B & num-B